[c#] Why do I get the error "Unsafe code may only appear if compiling with /unsafe"?

Why do I get the following error?

Unsafe code may only appear if compiling with /unsafe"?

I work in C# and Visual Studio 2008 for programming on Windows CE.

This question is related to c# visual-studio-2008 windows-ce unsafe

The answer is


Probably because you're using unsafe code.

Are you doing something with pointers or unmanaged assemblies somewhere?


To use unsafe code blocks, open the properties for the project, go to the Build tab and check the Allow unsafe code checkbox, then compile and run.

class myclass
{
     public static void Main(string[] args)
     {
         unsafe
         {
             int iData = 10;
             int* pData = &iData;
             Console.WriteLine("Data is " + iData);
             Console.WriteLine("Address is " + (int)pData);
         }
     }
}

Output:

Data is 10
Address is 1831848

Here is a screenshot:

Unsafe screenshot

????????


Search your code for unsafe blocks or statements. These are only valid is compiled with /unsafe.


For everybody who uses Rider you have to select your project>Right Click>Properties>Configurations Then select Debug and Release and check "Allow unsafe code" for both.Screenshot