After fixing my problem as mentioned here I am getting the below exception
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
My library is a .NET Standard 1.4 and the WebApp is .NET Framework 4.6.1
System.Data.SqlClient is version - 4.3.0 NuGet package. So I tried doing the below but in vain:
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlClient" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="4.1.0.0" newVersion="4.3.0.0"/>
</dependentAssembly>
I guess you may have figured it out already but hope it would save someone precious time
In order to make everything work you would need to reference System.Data.SqlClient in WebApp .NET Framework 4.6.1 project that is referencing your .NET Standard Library. After that everything should work just fine.
Sounds like .NET Standard Library haven't grabbed with itself dependent library binary. There is nothing like "Copy Local" option in .NET Standard references so I don't see any way to check or set this behavior too
We resolved this by adding System.Data.SqlClient
as a reference to our netstandard package, just using the nuget package manager. Once that was done Visual Studio did the rest in the Web solution.
It seems like the dependencies are not all added to the netstandard library when adding a package like Dapper.
What I tried:
I was also having the same error. I created a sample web api(2.0) which uses a .net standard 2.0 class library. In this library I am using Dapper and Dapper.Contrib and using their extension methods tried to query db. But was having the same error. I tried adding System.Data.SqlClient nuget package in the class library but it did not work. I am using VS2019 Community Edition. This has happened to me twice. So writing the exact scenario and solution that worked for me.
What Worked:
It was eventually resolved by removing System.Data.SqlClient nuget package from the class library and re-adding it in WebApi.
Which is strange since class library is able to resolve dapper nuget package but not System.Data.SqlClient, from within itself.
来源:https://stackoverflow.com/questions/43521867/system-io-filenotfoundexception-with-sqlclient