Unsafe Code Compilation error in .Net Core even af

2019-03-23 09:21发布

问题:

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, }

Still this error comes error CS0227: Unsafe code may only appear if compiling with /unsafe

I had already gone through this already

Unsafe code won't compile on Visual Studio 2015

How to call unsafe code from ASP.NET xproj

回答1:

Change compilationOptions to buildOptions:

"buildOptions": {
    "allowUnsafe": true
}


回答2:

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

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

in any PropertyGroup.