-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CommunityToolkit.Mvvm source generators fail on Visual Studio 17.4.0 Preview 6 and 17.5.0 Preview 1 #493
Comments
Mmh this is weird. Just to clarify:
|
It first reproduced when I updated Visual Studio to the 17.4.0 Preview 6 and some package dependencies. Downgrading CommunityToolkit.Mvvm from 8.1.0-Preview1 to 8.0.0 didn't help, and I managed to work around it by downgrading Microsoft.Windows.CsWin32 from 0.2.104-beta to 0.2.63-beta 😕. After updating VS to 17.5.0 Preview 1 it doesn't work anymore. |
Im stuck with below errors after upgrade
|
It reproduces for VS 17.4 stable, for version 8.0.0 and 8.1.0-preview1 both. |
In decompilation, the A workaround is to run |
Yesterday I was trying to work out why the source generators sometimes worked with WPF (,NET Framework 4.7.1) App and sometimes didn't. This morning I update VS 2022 to 17.4.1 and the source generators have stopped working completely. Testing with the following code in a class definition.
The solution builds but then the expected property FirstName is not generated by the source generator. If I look under References\Analyzers the Analyzers node is not expandable. Steps to reproduce, Create a new WPF Desktop App (.NET Framework 4.7.1) Build. Additional info... If I convert packages.conf to ReferencedPackages and include transitive assemblies by ticking the top level box then the source generation starts but it leads to a whole load of messages at the top of the Visual Studio IDE. and the following build errors. The stack trace of the first messages is:
In all there are 12 messages they all seem to have the same stack trace. 'IntroduceVariableCodeRefactoringProvider' encountered an error and has been disabled. |
On our build environment at the customer we also have this issue. We can't see any difference in the generated csproj file when looking at the msbuild binlog file :-( |
Given that there's a whole bunch of inbox analyzers also failing for the same reason, this seems unrelated from the MVVM Toolkit specifically. Also note that the generators have known issue with non-SDK-style .NET Framework projects. Does the issue still repro for you if you switch to an SDK-style .csproj format? |
I'm using .NET 7, VS2022 17.4.2, SDK style project Still can reproduce these,@Sergio0694 <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.138-beta">
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.164-beta"> |
I have the same issue which is also intermittent and I have no idea what triggers it and how it gets resolved. My error message happens with RelayCommand:
There is nothing that seems to be a proven workaround if using VS. Deleting all obj / bin folders does not help. The only thing that helps is switching to VS Code and after a while switching back to VS. I also use I have an SDK-style .NET 7 project where this happens. |
@virzak I solved this by downgrade the Cswin32 version, save and close proj, reopen vs ,and then manually upgrade back by editing the csproj file. |
This is... Uh... Weird. I don't think different generators should/could interfere with one another 🤔 FYI @sharwell |
@Sergio0694 VS17.4.3 has fixed this issue |
Sweet, thanks! I'll close this as external then 😄 |
I still don't think this is fixed yet. I'm still getting the same error on a personal project of mine. Installed v17.4.3 in a Windows Sandbox since I normally use the preview versions (and was still seeing the error in 17.5p2) CommunityToolkit: v8.1.0-preview2
|
Just to clarify:
|
I'm putting together a minimal repro now. |
Exactly Microsoft.Windows.CsWin32: v0.2.164-beta. |
Only with CsWin32, above version 0.2.138-beta. I'll post and issue over there as well. Edit: As stated below, it may be an even lower version but the warnings may not be as evident. CsWin32 updated Quick repo > mkdir CTRepro
> cd CTRepro
> dotnet new wpf
> dotnet add package CommunityToolkit.Mvvm -v 8.1.0-preview2
> dotnet add package Microsoft.Windows.CsWin32 -v 0.2.164-beta Then add a using CommunityToolkit.Mvvm.Input;
namespace CTRepro;
internal partial class MainWindowViewModel
{
[RelayCommand]
private void Execute()
{ }
} You can do either one of these. MSBuild will at least warn you something went wrong.
or
What's even worse is that Here's the binlogs from |
This is... Very weird. I would say I have no idea what's going on. It would seem like CsWin32 is somehow interfering with the toolkit, but even then... How? Like, maybe a .targets that's accidentally interfering with other analyzers? 🤔 Marking this as external for now as it does seem unrelated to the MVVM Toolkit. |
Maybe I was too quick with my judgement. So here is what I observed. Then there was one place where I had something like this: To make sure there was no other influence, I restarted my computer, cleaned the whole temp directory, build the solution from scratch and for now, the Analyzer is happy. I then created a test project which contains the scenario in isolation.
First, Roslyn was not happy (unfortunately Rider is a bit hard to debug in that regard). So in the end, it could have been me who accidentally had the Class Name as the Property Name in the generated source. |
@Sergio0694 I've updated everything on my end, and I'm no longer seeing the problem! However I think I have to play around with it some more to confirm. |
I'm on 8.2.0 and VS 17.6.1 and the problem is still there. |
@Balkoth can you provide some specific messages you are observing with these versions when the errors appear? |
I'm experiencing the same thing; where can I look for the messages? The source generator just appears to stop working; restarting Visual Studio fixes it for a short time, but I'm restarting at least a dozen times a day. |
@Sergio0694 update: after several days of use, I can confirm the issue is still here. Over a small period of time, I can code normally and never see this issue. However, some time after that I start seeing the problem again. Now just like before, as soon as I do anything related to the CommunityToolkit.Mvvm (even as simple as placing Still, for me, the only temporary solution to this problem is to clean the solution, close Visual Studio, manually delete all my bin and obj folders, and re-launch Visual Studio. I'm using the latest release version of Visual Studio and CommunityToolkit.Mvvm. |
Same thing for me - however, as all my mvvm related code is on a separate library project - I juste need to "Unload Project" and reload it, then every thing is fine (no need to quit VS, delete bin and obj folders) |
the important thing is it stops the hot reload :cry |
Based on the feedback it seems like we addressed part of the problem but not all of it here. Unfortunately the inability to have a reliable repro is making it difficult to track down this issue. It's not even clear right now if there is a bug in the roslyn side or in the mvvm generator. One item we're going to try on our end is expand our diagnostic capabilities:
Taken together those two issues should let us view the internal mechanics of generators if you submit an ETL trace. That should be integrated into the VS feedback system such that it can be automated to a large degree. Our goal is to get this all implemented in time for VS 17.7 Preview 3 or Preview 4. Hopefully that's in time for you all to send us ETL traces with the expanded diagnostics and we can track down where the remaining issues are. |
@jaredpar I have a (pretty consistent) repro!! 🎉
With these steps, I can pretty consistently get the generator to crash. It doesn't always happen though. One time it didn't work, but after closing and reopening VS, doing the same steps did reproduce the issue. Happens almost all the times. Error message:
Also happy to share more from my end if you need (eg. if there's a way to collect more telemetry for you or anything).
Not excluding there might be a bug in the MVVM Toolkit, but FWIW this repro is using a different generator (the one for Does the repro help? |
That is generally indicative of a bug in the generator though, not roslyn. It's asserting that you provided the same hint name twice. Have you debugged in to make sure you're not doing this? |
@jaredpar @Sergio0694 This sounds a lot like a previous issue we had where we were incorrectly handling removed entries: dotnet/roslyn#66643 I would bet that this is probably the same kind of issue. |
@Sergio0694 As an aside, I feel like this is the first time we're actually seeing the |
Ok I have investigated this a bit, if it's an issue in my generator I have to be honest I just don't see it 🥲
So it seems the only way to reproduce the issue (at least, in this case) is if the incremental models compare to be equal across pipelines. I am also a bit confused as to why using a new guid from the output node doesn't result in a build error in case the generator driver was in fact accidentally passing the same model twice (which would explain the
Not sure, this is the only case that I can consistently reproduce locally, not sure about others. Hopefully others in this thread that have also encountered the issue (especially with the other generator, for observable properties) can also comment. |
I was experiencing However, I'm not entirely sure it's gone forever as previously error appeared spontaneously when jumping between different commits of MahApps.Metro (linked as project reference to my app, not nuget) and did not go away after going back to the commit I started with. Cleanups, manually removing bin&obj, restarting VS - nothing helped. Project details: WPF MVVM app, built on top of MahApps.Metro, targeted to .NET Framework 4.8 & NET 6.0 Windows, CommunityToolkit.Mvvm 8.0.0, View Model with generated properties placed in the same project as main UI (with |
Not sure this is of much use, but updating to 17.6.2 from a much older version (17.3.something) solved this issue for me. Am a novice coder and was following the ".NET MAUI Data Binding with MVVM & XAML [5 of 8] | .NET MAUI for Beginners" youtube tutorial from the dotnet team and got this issue. Will leave a comment about this solution on the YouTube video as well as the option to downgrade to 8.0. Sadly didn't think to document the 60+ errors and warnings (which seems like more than others getting the same issue) I was getting on 8.2, but outside of using the 8.0 version the build would fail and the source code generators would not generate any files. |
The last issues related to this have been addressed by dotnet/roslyn#68451. |
It's still happening on Visual Studio for Mac version 17.6 (build 1575). |
@DanielD You can write the following in a source file to see the compiler version in use:
The fix would only be in Roslyn 4.7 and higher. |
Hi @Sergio0694, would you happen to know when this will likely reach the current channel for mainstream use? I know that it is 3 months or so after the preview is released |
Sorry, we can't share ETAs on when will public releases of Visual Studio will be released 🥲 |
@Sergio0694 Thanks for the update and quick response 🙂 |
Its still happening on WPF + .NET 7.0 + VS 17.6.5 + MvvmToolkit v8.2.1,. |
I observe probably the same issue: I use Mvvm to generate properties and commands.
IntelliSense does not show errors and I can see the generated code under "Analyse". I do not observe this issue within library projects of the same solution (same target framework, same toolkit). I have not found a workaround. The source generator is just not working for me. Update: |
@mscholz5 That does not sound like the same issue. Can you file a new issue? |
I filed #750. |
This issue is also happening for me on 17.8.0 Preview 7.0 and 8.2.2. |
@LancashireDave this should have been resolved; can you see if it's similar to #750 or file a new issue to provide more information? |
Describe the bug
I recently updated Visual Studio to 17.5.0 Preview 1.0 and my project starts to fail to build.
Regression
No response
Steps to reproduce
Expected behavior
It works.
Screenshots
No response
IDE and version
VS 2022 Preview
IDE version
No response
Nuget packages
Nuget package version(s)
8.1.0-preview1
Additional context
I can't always reproduce this. I'm also not sure if it's a problem in this project, but my other source generator dependencies are not affected.
Help us help you
Yes, but only if others can assist
The text was updated successfully, but these errors were encountered: