You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MVVM Toolkit Source Generator error Unsupported C# language version #613
MVVM Toolkit 8.1.0 Code Generator fails with error Unsupported C# language version.
The error description says: The source generator features from the MVVM Toolkit require consuming projects to set the C# language version to at least C# 8.0. Make sure to add <LangVersion>8.0</LangVersion> (or above) to your .csproj file.
I am running Visual Studio 2022, .NET 6.0 which should be using C# 10.0 by default. Adding <LangVersion>8.0</LangVersion> or <LangVersion>10.0</LangVersion> to the csproj file did not resolve the error.
I am trying to create a WinUI3 project, but have seen the same error reported on StackOverflow by someone who was creating a MAUI project.
This error does not appear when using MVVM Toolkit version 8.0.0
Regression
No response
Steps to reproduce
Windows 10
Visual Studio 2022, version 17.4.5
Create project Blank App, Packaged (WinUI3 in Desktop)
Update Nuget Packages to:
Microsoft.WindowsAppSDK 1.2.230118.102
Microsoft.Windows.SDK.BuildTools 10.0.22621.755
Install Nuget Package:
CommunityToolkit.Mvvm 8.1.0
In Solution Explorer Window, expand Dependencies->Analyzers->CommunityToolKit.Mvvm.SourceGenerators
Error messages are visible
Source generators do not generate any code.
Expected behavior
There should be no C# language version error and Source Generators should generator code.
I have the same exact problem using version 8.1.0.
Version 8.1.0 gives me the "Unsupported C# language version" message.
Then, as soon as I add a new property inside a class that makes use of the mvvm attributes, the source generator seems to fail as intellisense underlines some existing observable properties as missing.
Version 8.0.0 works fine though : no error message at all under the source generator node and the source generators don't fail when I add code in classes.
I've created a new WinUI3 project from scratch and added a few observable objects to make use of the attributes.
I've imported the 8.0.1 version.
I still get the error messages :
The difference in this case is that, unlike my work related projects, the source generators doesn't randomly fail when I add properties throughout files. These work related projects have many other references and I'm not sure how one of them could make the source generators fail ?
Those are not error messages. That's just VS showing you that the generator can produce those diagnostics, as they're declared in the various analyzers. But those being there is not an actual warning at all 🙂
Because in 8.0 all those diagnostics are produces by source generators, whereas in 8.1 we moved most of them to diagnostic analyzers (eg. see #433 and #581). The benefit is that diagnostic analyzers run out of process and asynchronously, so moving the diagnostics there help keep the IDE faster and more responsive, as the generators have less work to do (since they run synchronously as you type instead). As a side bonus, diagnostic analyzers explicitly declare all diagnostics they can potentially produce, so VS also shows all of them in that list, which also gives you the ability to optionally override the severity of each of them, if you want. So it's both faster and more configurable 🙂
Activity
woz6 commentedon Feb 20, 2023
Misunderstood what I was looking at. Seems to be working. Sorry for any time wasted.
stevehemond commentedon Apr 11, 2023
This seems to be an issue.
I have the same exact problem using version 8.1.0.
Version 8.1.0 gives me the "Unsupported C# language version" message.
Then, as soon as I add a new property inside a class that makes use of the mvvm attributes, the source generator seems to fail as intellisense underlines some existing observable properties as missing.
Version 8.0.0 works fine though : no error message at all under the source generator node and the source generators don't fail when I add code in classes.
Sergio0694 commentedon Apr 11, 2023
Would you be able to share a minimal repro?
stevehemond commentedon Apr 11, 2023
These are work related repos and not shareable.
I've created a new WinUI3 project from scratch and added a few observable objects to make use of the attributes.
I've imported the 8.0.1 version.
I still get the error messages :

The difference in this case is that, unlike my work related projects, the source generators doesn't randomly fail when I add properties throughout files. These work related projects have many other references and I'm not sure how one of them could make the source generators fail ?
Sergio0694 commentedon Apr 11, 2023
Those are not error messages. That's just VS showing you that the generator can produce those diagnostics, as they're declared in the various analyzers. But those being there is not an actual warning at all 🙂
stevehemond commentedon Apr 11, 2023
Ok, so, why these warnings are not showing up when using the 8.0.0 version ?
Also, that makes me really wonder why the source generators from the 8.0.0 doesn't fail while the 8.0.1 fails ...
Sergio0694 commentedon Apr 11, 2023
Because in 8.0 all those diagnostics are produces by source generators, whereas in 8.1 we moved most of them to diagnostic analyzers (eg. see #433 and #581). The benefit is that diagnostic analyzers run out of process and asynchronously, so moving the diagnostics there help keep the IDE faster and more responsive, as the generators have less work to do (since they run synchronously as you type instead). As a side bonus, diagnostic analyzers explicitly declare all diagnostics they can potentially produce, so VS also shows all of them in that list, which also gives you the ability to optionally override the severity of each of them, if you want. So it's both faster and more configurable 🙂
Sergio0694 commentedon Apr 11, 2023
That might be related to #493, which is a separate issue.