Share via

winUI3 with mvvm toolkit and get build error

Eduardo Gomez 4,316 Reputation points
2026-02-17T20:18:57.58+00:00

I am using mvvm with mvvm toolkit and get these errors

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<LangVersion>preview</LangVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>EasyShere</RootNamespace>
  <ApplicationManifest>app.manifest</ApplicationManifest>
  <Platforms>x86;x64;ARM64</Platforms>
  <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
  <PublishProfile>win-$(Platform).pubxml</PublishProfile>
  <UseWinUI>true</UseWinUI>
  <WinUISDKReferences>false</WinUISDKReferences>
  <EnableMsixTooling>true</EnableMsixTooling>
  <Nullable>enable</Nullable>
</PropertyGroup>

The modifier 'partial' is not valid for this item in C# 12.0. Please use language version '13.0' or greater.

This project has a transitive dependency on the full Windows SDK projections (including Windows.UI.Xaml.* types), but does not specify the UseUwp property. That must be enabled to ensure that .NET types are projected and marshalled correctly for interop scenarios with these XAML types.

Using [ObservableProperty] on partial properties requires the C# language version to be set to 'preview', as support for the 'field' keyword is needed by the source generators to emit valid code (add <LangVersion>preview</LangVersion> to your .csproj/.props file)

Windows development | WinUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 14,960 Reputation points Microsoft External Staff Moderator
    2026-02-18T04:50:45.1633333+00:00

    Hi @Eduardo Gomez ,

    Thanks for reaching out.

    I will address each issue:

    1. C# version / partial error

    “The modifier 'partial' is not valid for this item in C# 12.0…”

    Even though you’ve set:

    <LangVersion>preview</LangVersion>
    

    the key detail is that preview maps to different C# versions depending on your installed .NET SDK.

    If your SDK is older, preview may still resolve to C# 12, but partial properties (used by the latest MVVM Toolkit source generators) require C# 13 preview.

    Please run:

    dotnet --version
    

    If you’re below 8.0.400, update your .NET 8 SDK. In SDK 8.0.400+, preview correctly maps to C# 13 preview, and the partial error should go away without any other changes.

    After updating, delete your bin and obj folders and rebuild.

    1. [ObservableProperty] error

    “Using [ObservableProperty] on partial properties requires the C# language version to be set to 'preview'.”

    This is actually a side effect of the first issue.

    Starting with CommunityToolkit.Mvvm 8.2+, the toolkit supports a new partial-property style that relies on C# 13 features.

    You now have two valid patterns:

    Field-based (works in C# 12 and earlier):

    [ObservableProperty]
    private string? _name;
    

    Partial-property style (requires C# 13 preview):

    [ObservableProperty]
    public partial string? Name { get; set; }
    

    Just make sure you're not mixing styles in the same project, and that your SDK supports C# 13 preview.

    1. Windows SDK / UseUwp error

    “This project has a transitive dependency on the full Windows SDK projections…”

    This typically happens when something in your dependency chain pulls in Windows.UI.Xaml.* types.

    Since you're building a WinUI 3 desktop app (not a UWP app), this setting does not mean you’re converting your app to UWP. It simply enables the correct Windows projection behavior for interop.

    Add this inside your existing <PropertyGroup>:

    <UseUwp>true</UseUwp>
    

    Also, I’d recommend removing this line if present:

    <WinUISDKReferences>false</WinUISDKReferences>
    

    Let the SDK manage its references automatically unless you have a specific reason to override it.

    Before rebuilding:

    1. Run dotnet --version -> update to 8.0.400+ if needed
    2. Ensure <LangVersion>preview</LangVersion> is set
    3. Add <UseUwp>true</UseUwp>
    4. Confirm CommunityToolkit.Mvvm is 8.2.0 or later
    5. Delete bin and obj, then rebuild

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-17T20:19:09.4233333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To resolve the build errors you're encountering with WinUI 3 and the MVVM Toolkit, consider the following steps:

    1. C# Language Version: The error message indicates that the modifier 'partial' is not valid for C# 12.0. You need to set your project to use C# 13.0 or greater. You can do this by updating your .csproj file to include the following line:
         <LangVersion>13.0</LangVersion>
      
    2. UseUwp Property: Since your project has a transitive dependency on the full Windows SDK projections, you need to enable the UseUwp property in your project file. Add the following line to your <PropertyGroup>:
         <UseUwp>true</UseUwp>
      
    3. ObservableProperty Support: The warning regarding [ObservableProperty] indicates that you need to ensure that the language version is set to 'preview'. If you have already included <LangVersion>preview</LangVersion>, make sure it is correctly placed in your project file.

    By making these adjustments, you should be able to resolve the build errors you're experiencing.

    0 comments No comments

Your answer

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