Unsafe code may only appear if compiling with /unsafe error

You get Unsafe code may only appear if compiling with /unsafe error when trying to debug or build unsafe code in Visual Studio. 

To fix this error, you need to set your project setting to build and/or debug unsafe code. 

To set unsafe build, go to your project in Solution Explorer.

Right click on Project Name and select Properties. 

Go to Build tab and select "Allow unsafe code" 

unsafe1.jpg


To debug unsafe code, go to Debug tab and select "Enable unmanaged code debugging"

unsafe2.jpg