Forum Discussion
Could not load file or assembly System.Data.SqlClient
I found a solution, without knowing why this is a solution, for this problem.
I have two projects:
1. ASP.NET Core-Web-API (.NET 6)
2. Class-Library (.NET Framework) (Framework v4.8)
The connection to the database happens with Dapper and System.Data.SqlClient. Both are added to the references of the the Class-Library, but not added to the dependencies of the the Web-API. This should work, because the Class-Library should provide the SqlClient and Dapper, but it doesn't. It provides only Dapper to the Web-API. Idk why, but I needed to add the System.Data.SqlClient with NuGet to my Web-API dependencies too. I'll never use the SqlClient in my Web-API in furure. Currently it's a bug in the ASP.NET Core-Web-API in my opinion. I would be very grateful, if someone could explain this behaviour to me.
Regards
alex-1337 anyone stumbles on this, the System.Data.SqlClient.dll will be copied with the class library, if you add the following lines to your class library's app.config:
<entityFramework>
...
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>