Repository navigation
Description
Describe the bug
When i add nuget package Microsoft.SqlServer.SqlManagementObjects 170.18.0 for SMO APIs(it also adds lot of dependecy packages), One of the dependency is Microsoft.Data.SqlClient, which is using old version of System.Memory 4.0.1.1 while package downloads 4.0.1.2.

we always get exception on SqlConnection.Open() function call. below is the fusion log:
Pre-bind state information
LOG: DisplayName = System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/ABB.SDS.SDK/host/Server/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5.LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\ABB.SDS.SDK\host\Server\MOMServices.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/System.Memory.DLL.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/System.Memory/System.Memory.DLL.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/Apps/Configurator/desktop/System.Memory.DLL.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/Apps/Configurator/desktop/System.Memory/System.Memory.DLL.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/System.Memory.EXE.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/System.Memory/System.Memory.EXE.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/Apps/Configurator/desktop/System.Memory.EXE.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/Apps/Configurator/desktop/System.Memory/System.Memory.EXE.
LOG: Attempting download of new URL file:///C:/ABB.SDS.SDK/host/Server/Apps/ABB.SDS.Batch.Accessors.Server/server/System.Memory.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
To reproduce
Use Microsoft.SqlServer.SqlManagementObjects 170.18.0 and exectute SqlConnection
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = Utility.GetConnectionString(connectionParameter);
if (connectionParameter.UseAuthenticationMode == AuthenticationMode.Sql)
{
SqlCredential cred = new SqlCredential(connectionParameter.UserName, connectionParameter.Password);
con.Credential = cred;
}
Server server = new Server(new ServerConnection(con));
// Open connection.
con.Open();
if (con.State != System.Data.ConnectionState.Open)
return false;
if (server.VersionMajor < connectionParameter.ServerVersionNumber)
{
throw new NotSupportedException("This SQL server version is not supported. The minimum version number is " + connectionParameter.ServerVersionNumber.ToString(CultureInfo.CurrentCulture));
}
return true;
}Expected behavior
A clear and concise description of what you expected to happen.
Further technical details
Microsoft.Data.SqlClient version: Nuget version 5.1.1
.NET target: 4.8
SQL Server version: 2019
Operating system: Windows Server 2016
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity
chandrashekharjoshi-abb commentedon Jul 6, 2023
Update:
if i change System.Memory nuget version to 4.5.4 which is 4.0.1.1, the i get error for System.Runtime.CompilerServices.Unsafe.
Pre-bind state information ===
LOG: DisplayName = System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/ABB.SDS.SDK/host/Server/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\ABB.SDS.SDK\host\Server\MOMServices.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
chandrashekharjoshi-abb commentedon Jul 6, 2023
Finally i could make it work by changing the version manually in packages.config file as below:
Kaur-Parminder commentedon Jul 7, 2023
@chandrashekharjoshi-abb I am looking into the issue. I will update here, once I have it reproduced. As a workaround you can give try to assembly-redirect.
chandrashekharjoshi-abb commentedon Jul 7, 2023
Thank you for the response, i have tried assembly redirect and it didn't fix the issue, but i can give it another try by referring to the link.
acardenaskma commentedon Aug 8, 2023
I am facing the same issue with Microsoft.Data.SqlClient v5.02. Assembly redirects won't work because I'm using an Excel COM add-in and don't have access to the Excel app config file. The only solution I have found so far is to add the redirect to the machine.config, but that's not practical for clients' computers.
JRahnama commentedon Aug 8, 2023
I faced similar issue while working on WinForms. I added the nuget from Nuget.org through visual studio nuget package manager and inside the app.config I set the value to be like below somewhere inside configuration tag:
Depending on what version you installed you can redirect to the correct number.
I did not check if adding the package could fix the issue without changing the app.config.
chandrashekharjoshi-abb commentedon Aug 9, 2023
Assembly redirect did not work for, since it created chain of errors, after solving one another appears.
for me final solution was to do below changes in package.config, changed to lower versions for below package.
jzs11 commentedon Aug 24, 2023
I am facing the same problem, and it ends up updating almost 50+ configs and add binding redirect everywhere for an enterprise software I am working on. 🤯🤯🤯🤯🤯🤯🤯
JohnyL commentedon Jan 4, 2024
Same problem here.
NowinskiK commentedon Mar 4, 2024
I have the same problem when trying to create SqlConnection object in PowerShell, see cold below:
Error:

The above issue also happens when you use the
SqlServermodule as it uses DaxFx underneath.jjrobert65 commentedon Apr 11, 2024
Same. Mine is a .NET Framework Web API generated by the latest VS 2022.
-Jeff
tomconneely commentedon May 28, 2024
I'm working on a Windows Forms application and I am receiving the error stating that "Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
Is there a fix for this issue?
Alexbits commentedon Jun 27, 2024
This helped me in my case
Saibamen commentedon Aug 21, 2024
The same for me when I was trying to update .NET Framework lib to use latest EF6
6.5.1together withMicrosoft.Data.SqlClientversion5.2.1and trying to use newMicrosoft.Data.SqlClientproviderCommand:
Add-Migration UpdateEF6 -ConnectionStringName DevEDIT @Alexbits code also worked for me. Thanks
iSemihCetin commentedon Sep 3, 2024
Hi, thanks for the suggestion, the solution worked.
Hi, thanks for the suggestion, the solution worked.
mrihung commentedon Dec 19, 2024
I had the exact issue and this is how I fix it:
app Settings
add key="System.Memory" value="bin\System.Memory.dll"
add key="System.Runtime.CompilerServices.Unsafe" value="bin\System.Runtime.CompilerServices.Unsafe.dll"
add key="Microsoft.Identity.Client" value="bin\Microsoft.Identity.Client.dll"
app Settings
AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveAssembly
Public Function ResolveAssembly(sender As Object, args As ResolveEventArgs) As Assembly
Dim baseDirectory = AppDomain.CurrentDomain.BaseDirectory
Dim appPath As String = Process.GetCurrentProcess().MainModule.FileName
Dim appName As String = Path.GetFileName(appPath)
Dim appConfig = New FileInfo(String.Format("{0}{1}{2}", baseDirectory, appName, ".config"))
edwardneal commentedon May 1, 2025
As of the latest versions (6.0.2, 5.2.3 and 5.1.7) of each SqlClient release, this should now be working properly. Can you re-test please?
mrihung commentedon May 1, 2025
@edwardneal, do you mean I can test it with the latest version of sqlClient (6.0.2)? What are the versions for System.Memory, System.Runtime.CompilerServices.Unsafe and Microsoft.Identity.Client? Thanks
edwardneal commentedon May 1, 2025
That's correct @mrihung. When you add a reference to any of those three versions from a .NET Framework 4.x project, it'll pull in transitive references to System.Memory 4.5.5, System.Runtime.CompilerServices.Unsafe 6.0.0, and Microsoft.Identity.Client 4.61.3.
It should also generate the correct binding redirects in the built application's app.config file (although some projects might switch that off with the "Auto-generate binding redirects" checkbox.)
mrihung commentedon May 5, 2025
@edwardneal I've tried it with the latest version of SqlClient but still have a similar issue as show below. Do you have any suggestion?
An error has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.
System.IO.FileLoadException (Inner exception: System.IO.FileLoadException) - Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\NetfxSystem.Configuration.ConfigurationManagerbinding issue on .NET Framework)FileLoadExceptionforSystem.Runtime.CompilerServices.Unsafeinstead ofSystem.MemoryAnalysis
This is a classic .NET Framework binding-redirect problem: when
Microsoft.Data.SqlClientis pulled in transitively (here viaMicrosoft.SqlServer.SqlManagementObjects), the consuming app'sapp.configdoesn't get correct<bindingRedirect>entries forSystem.Memory/System.Runtime.CompilerServices.Unsafe/Microsoft.Identity.Client, so the runtime fails to load the version SqlClient's assembly actually references. It affectsnet462consumers who don't (or can't) auto-generate binding redirects, or whose host app manually loads assemblies viaAssembly.LoadFrom. Severity is P2 — impactful for affected consumers but has known workarounds (manualAssemblyResolvehandler, adding explicitPackageReferences) and partial fixes have already shipped.Next Steps
FileLoadExceptions across dependencies (System.Memory→System.Runtime.CompilerServices.Unsafe→ potentiallyMicrosoft.Identity.Client), recommend assigning to Copilot coding agent to audit thenet462reference assembly dependency versions and nuspec dependency group declarations inMicrosoft.Data.SqlClient.csproj/nuspec against.github/instructions/3rd-party-package-versions.instructions.md, confirming binding redirects match the versions actually consumed onnet462.PackageReference, e.g. toSystem.Configuration.ConfigurationManager, resolved a similar problem) as a possible workaround to document for affected users.System.MemorytoSystem.Runtime.CompilerServices.Unsafeacross SqlClient versions, verify whether a residual dependency-version mismatch still exists in the latest release before considering this fully resolved.