sashang
sashang

Reputation: 12214

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe'

Trying to use SQLTypeProvider with postgres I get the following errorwhen running

dotnet build

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. [/home/sashan/code/titan/src/Server/Server.fsproj]

my data provider is this:

type SQL = SqlDataProvider< 
                  ConnectionString = pg_dev_conn_string,
                  DatabaseVendor = Common.DatabaseProviderTypes.POSTGRESQL,
                  UseOptionTypes = true >

If I change it to the following

type SQL = SqlDataProvider< 
              ConnectionString = pg_dev_conn_string,
              DatabaseVendor = Common.DatabaseProviderTypes.POSTGRESQL,
              ResolutionPath = "/home/sashan/code/dotnet/2.1.500/sdk/NuGetFallbackFolder/system.runtime.compilerservices.unsafe/4.5.1/lib/netcoreapp2.0",
              UseOptionTypes = true >

The error goes away but I don't understand why. The fix seems really weird. Why should I have to point it to a file outside of my project? Shouldn't the System.Runtime.CompilerServices.Unsafe.dll be somewhere in one of project's subdirectories where the compiler can find it?

Upvotes: 10

Views: 28624

Answers (4)

carloswm85
carloswm85

Reputation: 2397

I don't know the exact cause of this problem (and other problems alike, which Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe'... But in my case the solution was:

  • Reinstall the System.Runtime.CompilerServices.Unsafe starting with all dependant packages.

Be sure you take note of the dependency tree (NuGet package name and version), you may need the information down the road.

Upvotes: 0

Prashant Manjule
Prashant Manjule

Reputation: 312

Try it in CMD,

you can find gacutil in(C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools>), and other installed frameworks in bin folder, try runs same commands for other '..\bin\NETFX x.x Tools' frameworks if necessary

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools>

gacutil -i "C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\net472\System.Runtime.CompilerServices.Unsafe.dll"

Upvotes: 3

Giancarlo Molina
Giancarlo Molina

Reputation: 101

i fix it comenting in web.config the entry that contains System.Runtime.CompilerServices.Unsafe

Upvotes: 5

Maryam
Maryam

Reputation: 125

I had the same problem with unity container and after updated this dll from Nuget my problem solved

Upvotes: 7

Related Questions