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.