Skip to content

MVVM Toolkit Source Generator error Unsupported C# language version #613

Closed

Description

@woz6

Describe the bug

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.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.4.5

Nuget packages

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

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

No, just wanted to report this

Activity

  1. added
    bug 🐛An unexpected issue that highlights incorrect behavior
    on Feb 20, 2023
  2. woz6 commented on Feb 20, 2023

    @woz6
    Author

    Misunderstood what I was looking at. Seems to be working. Sorry for any time wasted.

  3. stevehemond commented on Apr 11, 2023

    @stevehemond

    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.

  4. Sergio0694 commented on Apr 11, 2023

    @Sergio0694
    Member

    Would you be able to share a minimal repro?

  5. stevehemond commented on Apr 11, 2023

    @stevehemond

    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 :
    image

    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 ?

  6. Sergio0694 commented on Apr 11, 2023

    @Sergio0694
    Member

    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 🙂

  7. stevehemond commented on Apr 11, 2023

    @stevehemond

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

  8. Sergio0694 commented on Apr 11, 2023

    @Sergio0694
    Member

    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 🙂

  9. Sergio0694 commented on Apr 11, 2023

    @Sergio0694
    Member

    "makes me really wonder why the source generators from the 8.0.0 doesn't fail while the 8.0.1 fails"

    That might be related to #493, which is a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions