'.NET Core 6/EF Core 6.referencing Microsoft.Data.SqlClient, Version=2.0.20168.4

We've created a Web API using .NET Core 6 and EF Core 6. In development environment all works good but when I do the publish application fails with an error

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'

Deeper down the stack trace it references EF Core operations.

EF Core is dependent on Microsoft.Data.SqlClient version 2.1.4 and that version exists in publish. Any idea what when wrong here?

Thanks a lot, Miki



Solution 1:[1]

thanks for the effort.

I found what was the problem.

My dotnet publish command needed --self-contained --runtime win-x64 so it includes runtime and the runtime doesn't need to be installed on the target machine.

Cheers, Miki

Solution 2:[2]

You can use something like this:

dotnet publish -c Release -r win-x64 --self-contained --verbosity d

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike
Solution 2 Dutt93