34

I use System.Data.SqlClient Version 4.4.3 for all .NET Standard 2.0 class libraries in my ASP.NET Core 2.0 project. Why do I get

Could not load file or assembly 'System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

when the project is published with VSTS to Azure App Service? And of course it perfectly works on my machine!

All this worked yesterday. But today I decided to update packages to:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
4
  • this happened to me one time and i still had an old reference to a previous version in my references. You may have to manually remove it Commented Mar 22, 2018 at 22:03
  • I just checked - I don't have such a reference. Commented Mar 22, 2018 at 22:04
  • I've had a lot of issues with 2.0.6. So I've stopped using it. Commented Mar 22, 2018 at 22:13
  • I just did the same - downgraded to 2.0.5. Let's see... Commented Mar 22, 2018 at 22:24

6 Answers 6

65

Don't know whether this is the same situation that I faced. I added System.Data.SqlClient via nuGet and it worked fine.

Sign up to request clarification or add additional context in comments.

4 Comments

That just worked for me too ... I had it in one project of the solution but not the other. The one that didn't had a "reference" to a different version of System.Data
My project was core 2.2 and the default reference (without adding via nuget) was pointing to .net 4.7.
My project started out as a working Core 2.2 project, and the 'file not found' issue for System.Data.SqlClient occurred after upgrading the project to Core 3.1. System.Data.SqlClient was not installed previously, but after installing it (v4.8.1 in my case), the issue went away. Just another breaking change for Core 3.1 I guess!
as per @RodneyEllis I had to add a reference to my nuget System.Data.SqlClient to my website project too, then it worked
8

Downgraded to

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />

and everything works again! Lost 4 hours today!!!

1 Comment

I figured that would work. I'm fairly certain I read somewhere that 2.0.6 at some serious bugs.
1

I had a similar issue to this today, I updated a number of packages including the All meta-package to 2.0.6. My app then wouldn't work quoting the error above. After a lot of investigation I did the following and it now seems to be working.

Connect to the Azure Web Site using FTP, navigate to the site -> wwwroot folder. Here I had a folder called "refs" and another called "runtimes". I deleted both of these folders (after taking a local backup), re-published my app and it worked!

Not sure why it worked but I thought this might be useful is someone stumbles across this with a similar issue.

1 Comment

Deleting the contents of the wwwroot folder worked for me. Thanks.
1

I got the same issue, SerializationException with message:

Unable to find assembly 'Microsoft.Data.SqlClient,  
March 3rd 2020 16:36:46Error
Version=1.0.19269.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'

but everything is ok with dll, issue was caused by invalid connection string, it takes me almost few hours to figure out what happens!

Comments

0

This happens when some dependent assembly uses old version of same library. To solve that you can use assembly redirecting, to force old library use newer version.

put this in your app.config or in web.config in case of asp.net

<dependentAssembly>  
    <assemblyIdentity name="System.Data.SqlClient"  publicKeyToken="b03f5f7f11d50a3a"  culture="neutral" />  
    <bindingRedirect oldVersion="4.2.0.2" newVersion="4.4.3.0" />  
</dependentAssembly>  

2 Comments

This is ASP.NET Core 2.0!
@alvipeo you can create app.config in asp.net core too, It will pick up assembly redirect rules
0

For me, the solution was removing the System.Data.SqlClient package and installing it again. Doing the upgrade of the package wasn't sufficient.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.