Could not load file or assembly 'System.Memory, Version=4.0.1.' in Visual Studio 2015
Asked Answered
F

12

39

For a couple of months i had no issue generating the model from DB by deleting it and recreating it . After a pull from git, an issue has been occurred while trying to make the same process . After the second step (connection string creation with DB) there is no further proceed at the 3rd step and no connection string with the data base is being created at the app.config file.I have tried to test the connection with the database credentials and i am getting the following .

connection test failed

When i try to update specific tables from the model diagram as an alternative i get also the below :

System.Data.Entity.Core.EntityException: An error occurred while closing the provider connection. See the inner exception for details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

I have reinstalled Entity Framework and npgsql packages and tried to add all (the same) assemblies but with no success . Similar answers at Stack did not solve my issue . (I am allowed to work with the current versions with no further updates at VS or any of its packages.)

!Notice : i get all the appropriate data from my services when i use the API calls with the current model (proper communication with DB), but i cannot generate a new model from DB .

Any solutions ?

I am using

  • Windows 10

  • VS 2015

  • EntityFrameWork 6.2.0

  • Npgsql 3.1.1

  • .Net v.4.6.2

  • Asp.net

    Thanks in advance !

Fornix answered 4/4, 2019 at 6:59 Comment(5)
install the nuget for the system.memory package, maybeUnsatisfactory
what sort of app is this? asp.net?Merril
Have you tried adding the System.Memory package (nuget.org/packages/System.Memory)? This could be caused through some inconsistencies in the Nuget packages, too (E.g. using 2 different packages with other versions as references from other packages).Collude
are you sure this started happening after a pull? can you see the changes in the .csproj of your project before the pull and after the pull?Kelly
A similar error had been occurred after the pull , then i deleted the file and cloned it . Then the current one occurredFornix
K
34

If this error is appearing in an IIS app such as ASP.NET, then there is a high probability that you are missing a binding redirect in the web.config.

When you install from Nuget, you should see a binding redirect in the web.config.

If you deploy the application to another machine but fail to set up the binding redirect on that secondary machine, then this error can appear.

<dependentAssembly>
  <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
Kindrakindred answered 14/6, 2021 at 15:40 Comment(8)
I had a similar problem, after upgrading System.Memory from 4.5.4 to 4.5.5 using NuGet.The correct version, to put there is "4.0.1.1" for System.Memory "4.5.4" and "4.0.1.2" for System.Memory "4.5.5".Faena
Thank you so much for that @BitQuestions. Using "4.0.1.2" fixed this issue for me. But how did you figure that out? I've got a nuget ref to version 4.5.5, and the dll I end up with from nuget has version 4.6.31308.1. So where does version 4.0.1.2 come from? The only way I've found to figure it out is to add the nuget package and see what gets generated in the config files, but do you know a better way? I can't find any reference to "4.0.1.2" in the nuget package.Gilemette
Oops. I should have checked below to @AirLancer's post before commenting: ildasm can show it to you in the MANIFEST section which had this text: 4:0:1:2. This is not at all obvious.Gilemette
For those who still struggle with this (like me): What you see in Windows Explorer as file version, is different than the assembly version: https://mcmap.net/q/409857/-dll-version-mismatch-issue So file version 4.6.31308.1 in Explorer is assembly version 4.0.1.2Kimbra
I had to use 4.0.1.2 as well.Tharp
You can find the assembly version listed in the nuget package - in the lib\[your-framework]\system.memory.dll - if you open that dll in 7-zip (for example) it will show you a folder called .rsrc, in which there is a version.txt containing all the different versions for the library.Ojeda
@Faena Could you, please, tell exact steps that you did? Thanks!Beirut
for rrreee and @johnyl who asked how I figured out, you need to install "NUGet Package Explorer", search the library, click on "show all versions" on the right, select the exact version you're using, double click on the version, then go to "lib\net461", and double click the specific dll. You'll need to search for "Strong Name" there, which will show you that magic number you need to put in the web.config. Looks like a long trip, but it's not at the end.Faena
P
9

Use IL Disassembler (ildasm.exe) to check if the version in your output directory matches the one in the error message.
Our software often runs into these kind of problems because different nuget packages require different versions together with a nasty mix of libraries not in nuget.
The need for different versions of the same library is not considered by the build process.

If the version mismatch is really the cause of your problem, you may be looking for binding redirects in you app.config to forward all older versions of that library to the newest one.
Something like this will need to be added to the <dependentAssembly> node of the library in question:

<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />

ildasm can usually be found here (depending on your Visual Studio version)
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\ildasm.exe

Predict answered 4/4, 2019 at 8:47 Comment(0)
M
4

Actually this answer come from a senior and he just helped to solve it! He said because the solution keep the old files -> this error, you can try to open each projects of solution and then remove folders 'bin' and 'obj' -> clean build again! Just an option you can try!

Matthew answered 6/2, 2020 at 4:52 Comment(0)
E
3

I just had a similar problem with a console app I'm working on. It was working fine last night. Today I got the error message "Could not load file or assembly 'System.Memory, Version=4.0.1.0...". I wasn't able to resolve this until I went into Configuration Manager for my Visual Studio Solution and changed Active solution platform from "Any CPU" to "x64". After rebuilding my program now works and no longer throws the exception.

Everick answered 7/9, 2020 at 21:32 Comment(0)
F
2

For some reasons, the specific nugget package was not installed properly and I had not the option to compare it with an older file because I had messed up the backup file. I cloned the repository again(even if I had to discard some progress).

Steps:

  1. I had .Net version issues by downloading via nugget package manager so I had to do it manually.

  2. I have downloaded the .nupkg file from https://www.nuget.org/packages/System.Memory/

  3. Extracted the dll with a batch file found in https://gist.github.com/fex80/976ff887acb825171de6

  4. Copied to the bin folder of the proper project .

  5. Rebuild the project and at last, it worked.

Fornix answered 4/4, 2019 at 9:46 Comment(1)
7zip also allows getting the dlls outKimbra
P
1

For me, it was as simple as removing System.Memory from my references, then adding it back again. Strange, I don't know why this happened.

Propjet answered 12/5, 2023 at 16:23 Comment(0)
I
1

Goto NuGet and Upgrade the System.Memory package to the next version fixed it for me!!!

System.IO.FileLoadException HResult=0x80131040 Message=Could not load file or assembly 'System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=ccxxxxxxxxx....' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source=Microsoft.Extensions.Primitives StackTrace: at Microsoft.Extensions.Primitives.StringSegment.Equals(String text, StringComparison comparisonType)

Ilene answered 26/7, 2023 at 21:49 Comment(0)
N
1

My application had multiple versions installed. I updated all projects in the solution to the latest version of System.Memory and everything was fine!

Ng answered 23/8, 2023 at 17:54 Comment(0)
S
0

From a quick google search I found this : https://github.com/GrillPhil/ServerlessRealtimeDemo/issues/1

I don't know if this is out to date, but have you tried setting your Target version to Windows 10, version 1803 (10.0; Build 17134) and Min version to Windows 10 Fall Creators Update (10.0; Build 16299) in your project properties?

enter image description here

Scabby answered 4/4, 2019 at 7:8 Comment(2)
We still do not know which kind of project the OP has. This might be useful depending on the project type (E.g. UWP, ASP.Net, ...)Collude
My mistake , i have seen the above solution which does not fit for me since i am using ASP.Net .Fornix
K
0

I started seeing the dreaded System.Memory binding error after using the .NET Upgrade Assistant on one of my unit test projects. This project has a post-build step to bring in some FSharp tooling to this CSharp project.

I needed to manually change the post-build event handler to a Target/Exec project XML elements. Once I did that, post-build action started working, and the System.Memory runtime error is no longer there. All tests pass, go figure.

Kekkonen answered 28/3, 2024 at 16:57 Comment(0)
B
0

I tried all the solutions suggested previously. However, nothing from these solution worked. The solution that finally worked was to add probing to assembly binding configuration.

 <configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;..\packages"/>
      </assemblyBinding>
   </runtime>
</configuration>

Hint to this was found in Microsoft article at https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/specify-assembly-location?source=recommendations

Brayer answered 19/6, 2024 at 6:1 Comment(0)
S
-2

The error message you provided indicates a System.IO.FileLoadException related to the loading of a specific assembly, 'System.Memory,' and its version along with its dependencies. Let's break down the error message:

System.IO.FileLoadException: This is the type of exception that was thrown. It's an exception related to file loading issues, often when loading assemblies or libraries.

Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51': This part of the error message specifies the assembly that could not be loaded. It includes the assembly name ('System.Memory') along with the version, culture, and public key token. In this case, it's looking for 'System.Memory' with version 4.0.1.1 and a specific public key token.

"or one of its dependencies": This indicates that the 'System.Memory' assembly has dependencies, and the error might also be related to one of those dependencies.

This error typically occurs when a specific version of an assembly is expected, but the requested version cannot be found or loaded. There are a few common ways to address this issue:

Check the assembly reference: Ensure that the reference to 'System.Memory' in your project is correct and matches the expected version, culture, and public key token.

Check the presence of the assembly: Verify that the required assembly, 'System.Memory,' and its dependencies are present in your project or in the designated folder.

Use the correct assembly version: If your project requires a different version of 'System.Memory,' update the reference in your project to match the required version.

Use binding redirects: If you can't update the reference and need to use a different version, you may consider using binding redirects in your application's configuration file (e.g., app.config or web.config) to map the requested assembly version to the available version.

Check the GAC (Global Assembly Cache): Ensure that the assembly isn't already present in the GAC with a different version, which could be causing conflicts.

Investigate dependencies: If the error mentions dependencies, make sure those dependencies are also correctly referenced and available.

Check for missing or corrupted files: Sometimes, the issue can be caused by a missing or corrupted assembly file. Make sure the assembly file is intact and available.

By addressing the above points, you can troubleshoot and resolve the 'System.IO.FileLoadException' related to loading the 'System.Memory' assembly and its dependencies in your application

Smallish answered 17/10, 2023 at 9:57 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Epiglottis
This guy is using ChatGPTGabriello

© 2022 - 2025 — McMap. All rights reserved.