0

I get this error:

Failed to emit module 'xyz': Changing the version of an assembly reference is not allowed during debugging: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' changed version to '4.1.2.0'.

Every time I try to "Edit and Continue" in VS2022, I get this error. How to fix it?

Repro:

  • Add a .NET Standard package like PropertyChanged.Fody to project B
  • Reference project B in a .NET 4.8 Winforms app A
  • Run the app and try to "edit and continue" code in project B
2
  • Would be interesting to see the full scope of thing you are doing, steps to reproduce, etc Commented Nov 7 at 0:27
  • @T.S. Why should I? I answered my own question with all the info necessary to help others? If you want to add a NetStandard package like PropertyChanged.Fody to a project, then reference that project B in a .Net 4.8 winform app. Run the app and try edit and continue code in project B. This was hardly worth a downvote. I'll edit my question so you can undo your downvote. Commented Nov 7 at 1:10

1 Answer 1

3

The key insight was the app runs with the System.Runtime.dll version 4.0.0.0, this confirmed that a NuGet package (from NETStandard.Library and one of its transitive dependencies) was bringing in a newer version of System.Runtime than the one baked into .NET Framework.

This 4.1.2.0 version is not the native GAC version - it’s a NuGet-delivered reference assembly, and was overriding the framework version during JIT and emit, which is why Edit and Continue broke in this particular project (not all in solution). Like the error states it doesn't support changing a DLLs version in the middle of a debug session.

To fix it I got the 3 open source reference projects that didn't have net4.8 targeted builds. These were targeting previous .Net 4.x or NETStandard builds and during debugging the dependency graph gets the latest DLL! I downloaded the open source projects, edited the projects targeting .Net 4.8, built them. Then removed the Nugets from main solution project(s), added the DLLs Refs now targeting net4.8 and now Edit and Continue works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.