I port my ASP.NET Core 3.1 web application from using SqLite to PostgreSQL. I have added the Npgsql.EntityFrameworkCore.PostgreSQL, but when I run the app I receive the error:
{"The database provider attempted to register an implementation of the 'IRelationalTypeMappingSource' service. This is not a service defined by EF and as such must be registered as a provider-specific service using the 'TryAddProviderSpecificServices'
What may be the reason?
How to fix it?
That is my csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-PropMan-8C0D01B4-BE2A-48A3-B409-053DFA948FB1</UserSecretsId>
<Platforms>AnyCPU;x64</Platforms>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.101" />
<PackageReference Include="AWSSDK.S3" Version="3.3.110.38" />
<PackageReference Include="Finbuckle.MultiTenant" Version="6.0.0-preview5" />
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="6.0.0-preview5" />
<PackageReference Include="Finbuckle.MultiTenant.EntityFrameworkCore" Version="6.0.0-preview5" />
<PackageReference Include="GridBlazor" Version="1.3.33" />
<PackageReference Include="GridMvcCore" Version="2.11.27" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.2" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-preview.4.20220.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-preview.2.20120.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0-preview.2.20120.8" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings - Copy.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
You are mixing different versions of EF Core: Microsoft.EntityFrameworkCore.SqlServer (and some other packages) use 3.1.2, Microsoft.EntityFrameworkCore uses 5.0.0-preview4, Npgsql.EntityFrameworkCore.PostgreSQL uses 5.0.0-preview5... That will not work. Align all EF Core packages to the same version.
Also, if you use EF Core previews, it's really recommended to use the latest one, i.e. 5.0.0-preview6.
Am closing as this is clearly a problematic csproj, but feel free to continue posting here if you need further help.
Ok, thnx. Do I need to add the package
Npgsql.EntityFrameworkCore.PostgreSQL.Design ?
No, that package was discontinued back in 1.1.0 and is no longer necessary.
Thanx, you are right. I have removed some of packages, some downgraded and now this error disappeared.
Most helpful comment
You are mixing different versions of EF Core: Microsoft.EntityFrameworkCore.SqlServer (and some other packages) use 3.1.2, Microsoft.EntityFrameworkCore uses 5.0.0-preview4, Npgsql.EntityFrameworkCore.PostgreSQL uses 5.0.0-preview5... That will not work. Align all EF Core packages to the same version.
Also, if you use EF Core previews, it's really recommended to use the latest one, i.e. 5.0.0-preview6.
Am closing as this is clearly a problematic csproj, but feel free to continue posting here if you need further help.