Efcore.pg: System.TypeLoadException when configuring DbContext

Created on 30 Jan 2019  路  17Comments  路  Source: npgsql/efcore.pg

Exception details

System.TypeLoadException
  HResult=0x80131522
  Message=Method 'PopulateDebugInfo' in type 'Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' does not have an implementation.
  Source=Npgsql.EntityFrameworkCore.PostgreSQL
  StackTrace:
   at Microsoft.EntityFrameworkCore.NpgsqlDbContextOptionsExtensions.UseNpgsql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 npgsqlOptionsAction)
   at ...OnConfiguring(DbContextOptionsBuilder optionsBuilder)
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.Set[TEntity]()
   (further StackTrace is omitted)

Environment

Microsoft.EntityFrameworkCore 3.0.0-preview.19074.3
Npgsql.EntityFrameworkCore.PostgreSQL 3.0.0-ci.1451

Most helpful comment

@CumpsD There is a prelease package that solved that issue for me.

All 17 comments

@KexyBiscuit Thanks for taking the time to test our preview and report this back to us!

Could you please post the contents of your .csproj?

@austindrenski Here they are.

Directory.Build.props

<Project>
  <PropertyGroup>
    <LangVersion>8.0</LangVersion>
    <ErrorReport>send</ErrorReport>
    <NullableContextOptions>enable</NullableContextOptions>
    <Version>0.1.0-preview.1</Version>
    <Authors>...</Authors>
    <Copyright>漏 ... 2019</Copyright>
    <PackageProjectUrl>https://dev.azure.com/...</PackageProjectUrl>
    <RepositoryUrl>https://dev.azure.com/.../_git/...</RepositoryUrl>
    <NeutralLanguage>en-US</NeutralLanguage>
    <Features>strict</Features>
    <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
  </PropertyGroup>
</Project>

....csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <AssemblyName>...</AssemblyName>
    <RootNamespace>...</RootNamespace>
    <TargetFramework>netstandard2.0</TargetFramework>
    <NoWarn>$(NoWarn);NU5105</NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsAsErrors />
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>...</Description>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.0.0-preview.19074.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.0-ci.1451" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0-preview1-27018-01" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\...\....csproj" />
  </ItemGroup>

</Project>

..\...\....csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <AssemblyName>...</AssemblyName>
    <RootNamespace>...</RootNamespace>
    <TargetFramework>netstandard2.0</TargetFramework>
    <NoWarn>$(NoWarn);NU5105</NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsAsErrors />
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>...</Description>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0-preview1-27018-01" />
  </ItemGroup>

</Project>

The Npgsql preview build is targeting EF Core 3.0.0-preview.18572.1. It's possible that the proxies package is referencing a newer preview.

Could you try rolling back Microsoft.EntityFrameworkCore.Proxies to the equivalent version and let us know if that works for you?

3.0.0-preview.18620.3 works perfectly.

Awesome, that means it's just a dependency conflict. Keep an eye out for our next preview release, that'll have an updated EF Core dependency.

Last known good version is 3.0.0-preview.19052.8.

@austindrenski wrote:

The Npgsql preview build is targeting EF Core 3.0.0-preview.18572.1.

@austindrenski @roji don't you think it would make sense to upgrade this to 3.0.0-preview.19074.3 asap?

The out of box experience for .Net Core v3.0.0-preview2 is bad and makes testing the preview harder than it needs to be if not impossible.

Try the following in Powershell in a .Net Core v3.0.0-preview2 environment:

mkdir Tmp
cd Tmp
dotnet new mvc --auth Individual
Remove-Item ./Data/Migrations -Recurse
dotnet remove package Microsoft.EntityFrameworkCore.Sqlite
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 3.0.0-ci.1459 --source https://www.myget.org/F/npgsql-unstable/api/v3/index.json
Get-Content ./Startup.cs | %{$_ -replace "UseSqlite","UseNpgsql"} | Out-File ./Startup2.cs -Encoding ASCII
Remove-Item ./Startup.cs
Rename-Item ./Startup2.cs ./Startup.cs
dotnet ef migrations add InitialCreate --configuration Release -p Tmp.csproj -c ApplicationDbContext -o ./Data/Migrations

@Brar You need this in your NuGet.config :shipit:

<add key="azure-dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />

Yeah, the real problem is that we didn't release 3.0.0-preview2... IIRC there hasn't been any incredibly important development there, and preview3 shouldn't be too far away, so we should probably just wait for that.

@roji wrote

preview3 shouldn't be too far away, so we should probably just wait for that.

... but being an impatient person (and being blocked by the fact that even current MyGet unstable packages don't work with preview2) I went ahead and tried what it needs to create 3.0.0-preview2 compatibility.
It turned out that the necessary changes are minimal and as I assume that they'll be needed for preview3 compatibility anyways, I'll file a PR.

Can you bump to net5.0 please? Getting something similar:

[21:57:38 FTL] Host terminated unexpectedly
System.TypeLoadException: Method 'Create' in type 'Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal.NpgsqlSqlTranslatingExpressionVisitorFactory' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=3.1.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' does not have an implementation.

@CumpsD There is a prelease package that solved that issue for me.

@CumpsD There is a prelease package that solved that issue for me.

May I ask which prelease package solve it? I got the same problem.

May I ask which prelease package solve it? I got the same problem.

Until we release 5.0 I'd go with the latest from the unstable feed. https://www.myget.org/feed/npgsql-unstable/package/nuget/Npgsql.EntityFrameworkCore.PostgreSQL

None of the prerelease versions is particularly instable and we're definitely interested in feedback if you run into problems this short before the release.

It should also be possible to use Npgsql.EntityFrameworkCore.PostgreSQL 5.0.0-rc2 with the final EF Core 5.0.0 (though I haven't tested). The final 5.0.0 release of Npgsql should come in a couple days.

It should also be possible to use Npgsql.EntityFrameworkCore.PostgreSQL 5.0.0-rc2 with the final EF Core 5.0.0 (though I haven't tested). The final 5.0.0 release of Npgsql should come in a couple days.

Works, thanks :)

After the upgrade I couldn't connect to my old database. Turns out the PostgreSQL option "standard_conforming_strings" has to be "on" or Npgsql refuses to connect. Since PostgreSQL 9.1 "on" is the default value but apparently in our internal database this was manually turned off.

The following statement solves the issue:

ALTER DATABASE <db> SET standard_conforming_strings TO 'on';
Was this page helpful?
0 / 5 - 0 ratings