Could not load file or assembly System.Data.SqlClient, Version=4.2.0.2 when I use System.Data.SqlClient Version 4.4.3

会有一股神秘感。 提交于 2019-12-08 14:56:17

问题


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" />

回答1:


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




回答2:


Downgraded to

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

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




回答3:


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>  



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/49439150/could-not-load-file-or-assembly-system-data-sqlclient-version-4-2-0-2-when-i-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!