System.IO.FileNotFoundException with SqlClient

Manti_Core picture Manti_Core · Apr 20, 2017 · Viewed 9.2k times · Source

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>

Answer

Bogdan K picture Bogdan K · Sep 2, 2017

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