16

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?

Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130
Shilpa Soni
  • 2,034
  • 4
  • 27
  • 38

2 Answers2

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
  • 1
    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
  • 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