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

2

26

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:

Hollander answered 31/8, 2016 at 18:14 Comment(2)
Try using "buildOptions" instead of "compilationOptions". The latter was renamed at some point, and you should get some sort of deprecation warning about it, although that may have been removed at some point.Nara
@EricMellino, you should make this an answer Get the credit! Also, thanks!Sokul
C
12

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
}
Crossbones answered 20/11, 2016 at 17:23 Comment(0)
R
67

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

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

in any PropertyGroup.

Rhetor answered 29/9, 2017 at 23:55 Comment(0)
C
12

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
}
Crossbones answered 20/11, 2016 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.