System.IO.FileNotFoundException with SqlClient

After fixing my problem as mentioned here , I get the following 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 .NET Standard 1.4 and WebApp is .NET Framework 4.6.1

System.Data.SqlClient is version - 4.3.0 NuGet package. So I tried to do the following, 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>

      

+7


source to share


3 answers


I think you may have figured this out by now, but hope it saves someone precious time.

To do everything, you will need to reference System.Data.SqlClient in the WebApp.NET Framework 4.6.1 project referencing your .NET standard library. After that, everything should work fine.



It looks like the .NET standard library did not grab the dependent binaries library with it. There is nothing better than the "Copy Local" option in the .NET Standard, so I see no way to test or set this behavior.

+12


source


We solved this problem by adding System.Data.SqlClient

our custom package as a reference, just using the nuget package manager. After that, Visual Studio did the rest in the web solution.



It seems that when adding a package like Dapper, not all dependencies are added to the netstandard library.

+2


source


What I have tried:

I had the same error too. I have created a sample web API (2.0) that uses the .net 2.0 standard class library. In this library I am using Dapper and Dapper.Contrib and their extension methods were trying to query the DB. But there was the same mistake. I tried to add the nuget System.Data.SqlClient package to the class library but it didn't work. I am using VS2019 Community Edition. This happened to me twice. So I'm writing the exact scenario and solution that worked for me.

What worked:

This was ultimately solved by removing the nuget System.Data.SqlClient package from the class library and re-adding it to WebApi.

Which is weird, since the class library is capable of resolving an unnecessary nuget package, but not System.Data.SqlClient, from within itself.

0


source







All Articles