Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Unsafe code won't compile on Visual Studio 2015
  • How to call unsafe code from ASP.NET xproj
like image 383
User1234 Avatar asked Aug 31 '16 18:08

User1234


2 Answers

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

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

in any PropertyGroup.

like image 156
Ray Avatar answered Nov 09 '22 15:11

Ray


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
}
like image 23
IAbstract Avatar answered Nov 09 '22 15:11

IAbstract