WARNING MVVMTK0045

Giorgio Sfiligoi 371 Reputation points
2025-03-21T09:15:06.2+00:00

Both with net8.0 and net9.0, at times I have a warning MVVMTK0045.

Following the instructions in the relevant documentation https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/errors/mvvmtk0045 does not clear the issue - on the contrary, VS reports errors MVVMTK0052 and MVVMTK0043.

The funny thing is that not all the properties in my code generate this warning.

I am puzzled.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,066 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    2025-03-24T09:27:11.2733333+00:00

    I can reproduce this issue. You can remove this warning by the following two ways:

    1. Use the CommunityToolKit.Mvvm version 8.3.2 instead of the CommunityToolKit.Mvvm version 8.4.0. This can make the warning disappeared directly.
    2. According to the official documment about MVVM Toolkit warning MVVMTK0045 and MVVM Toolkit error MVVMTK0041.

    You can add the following code into the csproj file:

    <PropertyGroup>
          <LangVersion>preview</LangVersion>
    </PropertyGroup>
    

    And then change your properties like following code to:

    public partial class BaseViewModel : ObservableObject
     {
         [ObservableProperty]
         public partial bool Isbusy { get; set; }
         [ObservableProperty]
         public partial string? Title { get; set; }
     }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.