Unsafe code compilation error in .NET Core even after setting allowunsafe flag to true in project.json

User1234 picture User1234 · Aug 31, 2016 · Viewed 9.2k times · Source

I am using some unsafe code in my .NET Core app. For that, I had made this change in the project.json file:

"compilationOptions": {
    "allowUnsafe": true,
}

However, I still get the error CS0227: Unsafe code may only appear if compiling with /unsafe.

I had already gone through this:

Answer

Ray picture Ray · Sep 30, 2017

In the newer *.csproj files, this is now:

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

in any PropertyGroup.