0

I'm getting an unusual error when trying to build my newly created ASP.NET Core 6 project. Although it was working fine for the last few days, this error started appearing suddenly:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The module was expected to contain an assembly manifest.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets

I tried changing the platform target to other options like x64 or x86, but this problem doesn't seem to come from the project itself. That is because, I created another project to see if it's still appearing. Turns out that this error being thrown even when I build my newly created project.

What could possibly go wrong? Should I reinstall Visual Studio 2022 (Community edition)?

EDIT Rebooting the system fixed it. This could probably be an issue in my hard disk too as Hans Passant has mentioned in the comments section below.

  • can you commit a reproducing project to github and share? – Lei Yang Mar 24 '22 at 03:48
  • Don't do anything drastic. Reinstalling VS won't fix it. Run chkdsk first to see how much damage was done. If you see a bunch of errors then replace the disk drive. If not, delete the file from the nuget cache. Best to have a look at it first with a hex viewer, if it is filled with zeros then get rid of the installed anti-malware product. – Hans Passant Mar 24 '22 at 05:17
  • System.Memory.dll is part of the runtime. (it's typically located at `C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.2`) Try reinstalling the .net 6.0 sdk. – PMF Mar 24 '22 at 06:35

0 Answers0