.net.net-coreunsafecoreclr

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


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:


Solution

  • NOTE:
    This answer is based on earlier .Net Core/Standard project formats written in json. For the new formatted csproj see Ray's answer.

    Change compilationOptions to buildOptions:

    "buildOptions": {
        "allowUnsafe": true
    }