Avalonia
Avalonia copied to clipboard
Exception when using Edit and Continue on Visual Studio 2019 for Windows
Describe the bug Exception when using Edit and Continue on Visual Studio 2019 for Windows
To Reproduce
- Created a new Avalonia MVVM Application via the Visual Studio extension. (Avalonia 0.10)
- Set a breakpoint anywhere
- Debug the application
- Breakpoint hit
- Make any code modification
- This error appears Severity Code Description Project File Line Suppression State Error CS7038 Failed to emit module 'AvaloniaApplication1': Changing the version of an assembly reference is not allowed during debugging: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' changed version to '2.1.0.0'. AvaloniaApplication1 1 Active
Expected behavior Don't crash
Desktop (please complete the following information):
- OS: Windows 10
- Version 0.10.0
This also happens in Rider
This only happens when modifying code at runtime in a module that references Avalonia. Other modules without a dependency on Avalonia can be edited at runtime and continued.
I suspect it may be due to compiling the Xaml not updating the debug information for some reason.
@csulmone Are you using Fody.PropertyChanged in AvaloniaApplication1 or does Avalonia inject some code at compile time like Fody?
I have same CS7038 error, when I change code during debugging.
A few years ago I had a similar problem when Fody.PropertyChanged was added to the project, but then they fixed something and the problem disappeared.
is there any fix for this? it makes me have to rebuild the project every time the code is fixed, and slows down the coding
I found the cause in my case. In all projects I have set TargetFramework to net5.0-windows
, but in one I had set net.5.0
. When I changed in this latest project to net5.0-windows
, the problem with inability to edit disappeared.
Unfortunately this issue still occurs with .NET 6 and Visual Studio 2022. Is there any intention to address this? Not being able to use Edit & Continue can be a major blow to productivity :(
I tried changing all projects to net6.0-windows but it made no difference in my case.
@RobertBeekman We also migrated to .NET6 and the problem returned. I have not found a solution for this. Maybe one of the NuGets is causing this problem.
Same here, a fresh install of VS 2022, projects re-targeted to .NET 6, and cannot try hot reload 😥
I think this is the wrong issue to talk about the problem. Mayby we should "report a problem" in Visual Studio or write an issue at https://github.com/dotnet/runtime/issues.
Any plans to take a look into it guys?
Edit and continue and hot reload are features that saves the developer a lot of time and they're not working in Avalonia...
You can find a draft there #5363
BTW is "Edit and Continue" connected to "Hot Reload" support? I mean, is there a way to enable "Edit and Continue" without enabling "Hot Reload"?
I say that because "Hot Reload" support PR (#5363) seems to be inactive.
Same problem. Any progress?
Hi, I register same issue both in Visual Studio and Rider.
Is there any progress? vs2022 .net6 still cannot hot reload. The hot reload function will greatly improve development efficiency.
same with 11-preview4 + .net7
Are there any plans to add edit and continue / hot reload for .net 7?
I encountered same issue when trying default Avalonia templates, but using templates from https://github.com/AvaloniaUI/Avalonia.Markup.Declarative hot reload works. Although, the state is not automatically updated in all cases.
Note that, this approach won't be suitable for everyone, as C# is used to define views markup instead of XAML.
my guess would be that Avalonia.Build.Tasks is modifying the assembly after a compile, which woould prevent hot reload from patching it since the hash would be different. We have the same problem in Fody
Hi @SimonCropp ,
may be related, yes. Do you know if there is any way to fix it or a workaround an user can do? Would be really neat.
Happy coding Tim
@timunie unfortunately, no i do not know of any workaround
.
A possible workaround could be working without xaml and write the views in C# code.
https://github.com/AvaloniaUI/Avalonia.Markup.Declarative
I didnt tested it!
Workaround is to target the same .NET target framework version as Avalonia does. I.e., it's either .NET 6 (in 11.0) or .NET Standard 2.0. Then hot reload in c# code works fine.
👀 Can't believe that it now finally works (I had to try it directly ^^). This is a huge step for the debugging experience 👍 . Good job guys.
@timunie I used edit and continue even before with Avalonia and it worked. It was a quite specific use case, when it didn't, see - https://github.com/AvaloniaUI/Avalonia/issues/5456#issuecomment-1547044071
But I guess it was a way bigger problem with 0.10, which is only netstandard.