question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

See original GitHub issue

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. image

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

Issue Analytics

  • State:open
  • Created 3 months ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chandrashekharjoshi-abbcommented, 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.

<package id="System.Memory" version="4.5.4" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
0reactions
JRahnamacommented, Aug 9, 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:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.6.0"
                         newVersion="4.0.6.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'System.Memory, Version= ...
Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. I have reinstalled Entity Framework and ...
Read more >
This is an unhandled exception in MSBuild -- PLEASE ...
FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one ...
Read more >
System.Memory.dll Version Mismatch in Visual Studio 2019
So I get the error: Can not load Assembly System.Memory ... Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.
Read more >
Could not load file or assembly 'System.Memory'
Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified ...
Read more >
Azure Storage Blob - Could not load file or assembly ...
Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. External ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found