dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Source Generator for [ObservableProperty] doesn't work anymore since upgrading to visual studio 17.11.2.

Open JorisZwaenepoel opened this issue 1 year ago • 9 comments

Describe the bug

I'm using the CommunityToolkit.Mvvm version 8.2.2.

Since I updated Visual Studio 2022 to the latest version 17.11.2, I keep having problems when adding new properties using [ObservableProperty]. The source generator doesn't work automatically, and some keyboard keys (like backspace or delete) don't work anymore. I have to close and restart Visual Studio to be able to continue my work.

I don't know if this is a Visual Studio bug or a toolkit bug.

If this cannot be fixed quickly, I would like to know what the most recent version of Visual Studio where this still works.

Regression

No response

Steps to reproduce

Update Visual Studio 2022 to version 17.11.2

Expected behavior

The sourcegenerator should make the required code for [ObservableProperty] properties on the background without messing up the editor experience.

Screenshots

image

IDE and version

VS 2022

IDE version

Version 17.11.2

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

No, just wanted to report this

JorisZwaenepoel avatar Sep 06 '24 09:09 JorisZwaenepoel

Is your code actually building correctly? Or does it eg. fail to build if you try referencing the generated property?

Sergio0694 avatar Sep 07 '24 19:09 Sergio0694

It builds correctly. But the editor is behaving weird (keyboard not functioning correctly, only inside of Visual Studio). After restarting Visual Studio, it works correct until I make a new ObservableProperty. Rolling back to version 17.10.6 of Visual Studio helped to get rid of the problem. A colleague has experienced the same issues with the same versions. The bug is probably in Visual Studio, not in the Mvvm Toolkit.

JorisZwaenepoel avatar Sep 08 '24 07:09 JorisZwaenepoel

Yeah this sounds like an issue in the IDE. Try reporting it either in the Roslyn repo or with VS Feedback, and link this one.

Sergio0694 avatar Sep 08 '24 08:09 Sergio0694

If you do raise an issue elsewhere please post back here that we can vote it up. I have also seen the IDE go nuts about the source generated files, but decided to just ignore it for the time being.

Balkoth avatar Sep 11 '24 15:09 Balkoth

I just raised the issue using Visual Studio feedback: https://developercommunity.visualstudio.com/t/Source-Generator-for-ObservableProperty/10743355

JorisZwaenepoel avatar Sep 11 '24 15:09 JorisZwaenepoel

I too had been noticing that source generators didn't seem to be updating nicely as they have in the past and I was needing to rebuild on 17.11.3, I noticed this response there in the issue from Joris:

In 17.11 Preview 2, we changed the default source generation execution behavior from “Automatic” to “Balanced”. The easiest action to trigger source generators in this mode is saving the current file. If you would like to restore the old behavior, the option can be found in Tools → Options… → Text Editor → C# → Advanced → Source generator execution.

Thank you, Sam Harwell

Seems like a big behavior change for those that rely on these features. I guess it's for performance reasons. Would be nice though if they could separate the options for the old source generators vs. the incremental ones or something too.

hawkerm avatar Sep 20 '24 05:09 hawkerm

I have no idea if the issues I had were related to this option setting, and I don't think I was using a preview version of Visual Studio either. Apart from the source generator not regenerating automatically, I also had keyboard issues in Visual Studio at the same time. Those were making it much more difficult to write code (especially the backspace and delete keys that were not working), and required a restart of Visual Studio.

JorisZwaenepoel avatar Sep 20 '24 05:09 JorisZwaenepoel

I too had been noticing that source generators didn't seem to be updating nicely as they have in the past and I was needing to rebuild on 17.11.3, I noticed this response there in the issue from Joris:

In 17.11 Preview 2, we changed the default source generation execution behavior from “Automatic” to “Balanced”. The easiest action to trigger source generators in this mode is saving the current file. If you would like to restore the old behavior, the option can be found in Tools → Options… → Text Editor → C# → Advanced → Source generator execution. Thank you, Sam Harwell

Seems like a big behavior change for those that rely on these features. I guess it's for performance reasons. Would be nice though if they could separate the options for the old source generators vs. the incremental ones or something too.

Thanks !! this made the source generation work as expected.

EDIT: nevermind, worked for like a minute or so ... now i have to build the project again for the source generator to run

mischiminator avatar Sep 25 '24 13:09 mischiminator

I'm having the same issue with Visual Studio 17.12.0 Preview 2.1, I think this issue is related to the ServiceHub.RoslynCodeAnalysisServiceS.exe skyrocketing in CPU and RAM usage. When this process "goes crazy", Visual Studio becomes unresponsive and stuff like F12 or "the squiggle" stops working for minutes. I've been able to repro this issue on two different machines -> related feedback https://developercommunity.visualstudio.com/t/ServiceHubRoslynCodeAnalysisServiceSex/10764773

Image

ilGianfri avatar Oct 09 '24 16:10 ilGianfri