How to resolve this error in VS2012 "Unsafe code may only appear if compiling with /unsafe”? I am not compiling from the command-line so I cannot simply add /unsafe. How can I compile unsafe code in VS2012?
            Asked
            
        
        
            Active
            
        
            Viewed 2.4k times
        
    16
            
            
        - 
                    1The message even tells you which option to pass to the compiler -- `/unsafe`! – devnull Jul 15 '13 at 09:05
 - 
                    possible duplicate of [Why do I get the error "Unsafe code may only appear if compiling with /unsafe"?](http://stackoverflow.com/questions/2026410/why-do-i-get-the-error-unsafe-code-may-only-appear-if-compiling-with-unsafe) – Kamil Budziewski Jul 15 '13 at 09:05
 - 
                    9You forget `vb.net` and `f#` tags. – Soner Gönül Jul 15 '13 at 09:05
 - 
                    2@Soner And C++/CLI, for completeness. – Daniel Daranas Jul 15 '13 at 09:07
 - 
                    @wudzik this question is regarding VS2008 or VS2010, but I was not able to resolve the problem in VS2012 because it does not contain the check box named "Allow unsafe code". – Shilpa Soni Jul 15 '13 at 09:09
 - 
                    @ShilpaSoni I have VS 2012 and did what's [explained on that link](http://stackoverflow.com/a/6771861/1169228). I can see the CheckBox just fine. – Nolonar Jul 15 '13 at 09:11
 - 
                    @Nolonar Is it because I have Microsoft VS express 2012? – Shilpa Soni Jul 15 '13 at 09:13
 - 
                    what project type you're working with? – Sriram Sakthivel Jul 15 '13 at 09:13
 - 
                    try this edit your *.csproj file in text editor navigate to PropertyGroup and add AllowUnsafeBlocks then save it and restart VS. ex: `
 ` – Sriram Sakthivel Jul 15 '13 at 09:18true  - 
                    @SriramSakthivel I just got the solution, Actually I was looking that option (Allow unsafe code) in website's properties. Now when I saw in project's properties I found the check box and my error got resolved. – Shilpa Soni Jul 15 '13 at 09:23
 
2 Answers
44
            Right click on your project. Select "Properties". Switch to the "Build" tab. Check "Allow unsafe code".
        nvoigt
        
- 75,013
 - 26
 - 93
 - 142
 
- 
                    I was not able to resolve the problem in VS2012 because it does not contain the check box named "Allow unsafe code" – Shilpa Soni Jul 15 '13 at 09:11
 - 
                    I'm sitting right in front of it. My version does have it. Maybe your version does not allow unsafe code or you need to reinstall. – nvoigt Jul 15 '13 at 09:14
 - 
                    1I just got the solution, Actually I was looking that option (Allow unsafe code) in website's properties. Now when I saw in project's properties I found the check box and my error got resolved. – Shilpa Soni Jul 15 '13 at 09:23
 - 
                    1@ShilpaSoni You should accept an answer; they both basically tell you to open the `Project > Properties`, which is how you solved your problem "by yourself". – Nolonar Jul 15 '13 at 14:06
 
7
            
            
        Open project properties, select Build tab and click on Allow unsafe code.
        Dayal rai
        
- 6,548
 - 22
 - 29
 
- 
                    I was not able to resolve the problem in VS2012 because it does not contain the check box named "Allow unsafe code". – Shilpa Soni Jul 15 '13 at 09:10