Unsafe code may only appear if compiling with /unsafe error

By Mahesh Chand Jul 26, 2012
You get Unsafe code may only appear if compiling with /unsafe error when trying to debug or build unsafe code in Visual Studio.
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
Mahesh Chand

Mahesh Chand is founder of C# Corner. C# Corner founded in 1999 is a FREE member contributions based open platform for developers to solve problems, learn new technology and hang out.  Mahesh has been awar... Read more

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs