Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Exception when using Edit and Continue on Visual Studio 2019 for Windows

Open sulmone opened this issue 3 years ago • 16 comments

Describe the bug Exception when using Edit and Continue on Visual Studio 2019 for Windows

To Reproduce

  1. Created a new Avalonia MVVM Application via the Visual Studio extension. (Avalonia 0.10)
  2. Set a breakpoint anywhere
  3. Debug the application
  4. Breakpoint hit
  5. Make any code modification
  6. 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

sulmone avatar Feb 09 '21 22:02 sulmone

This also happens in Rider

rstm-sf avatar Feb 10 '21 19:02 rstm-sf

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.

sulmone avatar Feb 11 '21 18:02 sulmone

I suspect it may be due to compiling the Xaml not updating the debug information for some reason.

workgroupengineering avatar Feb 12 '21 08:02 workgroupengineering

@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.

marbel82 avatar Jun 09 '21 13:06 marbel82

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

unofficialdev avatar Jun 14 '21 10:06 unofficialdev

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.

marbel82 avatar Sep 10 '21 07:09 marbel82

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 avatar Jan 08 '22 16:01 RobertBeekman

@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.

marbel82 avatar Jan 10 '22 10:01 marbel82

Same here, a fresh install of VS 2022, projects re-targeted to .NET 6, and cannot try hot reload 😥

oli-g-sk avatar Jan 10 '22 19:01 oli-g-sk

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.

marbel82 avatar Jan 10 '22 19:01 marbel82

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...

danipen avatar Feb 01 '22 09:02 danipen

You can find a draft there #5363

workgroupengineering avatar Feb 01 '22 10:02 workgroupengineering

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.

danipen avatar Mar 02 '22 08:03 danipen

Same problem. Any progress?

yll690 avatar Jun 29 '22 07:06 yll690

Hi, I register same issue both in Visual Studio and Rider.

turboluk avatar Jul 20 '22 08:07 turboluk

Is there any progress? vs2022 .net6 still cannot hot reload. The hot reload function will greatly improve development efficiency.

sudongg avatar Aug 01 '22 09:08 sudongg

same with 11-preview4 + .net7

yingDev avatar Nov 29 '22 09:11 yingDev

Are there any plans to add edit and continue / hot reload for .net 7?

danipen avatar Nov 29 '22 10:11 danipen

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.

Jure-BB avatar Dec 27 '22 23:12 Jure-BB

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

SimonCropp avatar Jan 03 '23 04:01 SimonCropp

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 avatar Jan 04 '23 07:01 timunie

@timunie unfortunately, no i do not know of any workaround

SimonCropp avatar Jan 04 '23 09:01 SimonCropp

.

unofficialdev avatar Apr 02 '23 03:04 unofficialdev

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!

svenhue avatar Apr 25 '23 14:04 svenhue

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.

maxkatz6 avatar May 15 '23 00:05 maxkatz6

👀 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 avatar May 16 '23 06:05 timunie

@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.

maxkatz6 avatar May 16 '23 19:05 maxkatz6