Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.13.20136.2
See original GitHub issueDescribe the bug
When making a database call with Microsoft.Data.SqlClient it is looking for the wrong version.
This application uses a combination of EntityFramework Core 3.1.9 and Microsoft.Data.SqlClient 2.0.1 calls.
Error Msg:Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.13.20136.2, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
Stack Trace:(no main stack trace available)
Expected behavior
I expected it to use the 2.0.1 version that is used and distributed with the application.
Further technical details
Microsoft.Data.SqlClient version: (found on the nuget or Microsoft.Data.SqlClient.dll) .NET target: (e.g. Framework 4.8) SQL Server version: (e.g. Azure SQL) Operating system: (e.g. Windows 10)
Additional context I have checked the entire solution and the only references I see are to Microsoft.Data.SqlClient 2.0.1 so I am not sure where it is getting this 1.13.20136.2 from. I have tried binding redirects with the following, which appears to be working but may be wrong (what is the best way to get the version needed here?).
<dependentAssembly> <assemblyIdentity name="Microsoft.Data.SqlClient" publicKeyToken="23ec7fc2d6eaa4a5" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.0.0" /> </dependentAssembly>
Not sure what to try next so hoping someone can put me on the path to understanding why it thinks it needs this old version. We use directory.build.targets for our nuget packages in this solution and in searching the solution there is no reference to any earlier version of Microsoft.Data.SqlClient.
Thank you in advance for any insight or suggestions.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Let me give it a try.
Beside
ildasm
orilspy
added in your visual studio you can use powershell. Basically, what you need to do is, install the package byInstall-Package -Name "Microsoft.Data.SqlClient" -Destination ".\temp" -Force -Source MyNuget -SkipDependencies
This will isntall the package in a folder namedtemp
, created in the same directory.MyNuget
can be defined as name variable for your provider or source. You can get list of your providers by runningGet-PackageProvider
after installing the package you can run:Get-ChildItem *.dll -Path .\temp -Recurse | ForEach-Object versioninfo
That will provide you a list like this:
in the FileVersion section you can find assembly versions.
The other option would be using NuGet Package Explorer and clicking on DLLs: