Share via

SourceGen adding getting build error

Bhuwan 1,221 Reputation points
2026-02-18T05:48:47.8366667+00:00

Hello,

I am getting the following errors after adding the below tags to my .csproj file:

<MauiXamlInflator>SourceGen</MauiXamlInflator>

<!-- Optional -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>

D:\Projects\MyApp\WebInterface\MAUIApp\obj\Debug\net10.0-android\generated\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.XamlGenerator\App.xaml.xsg.cs(44,335): error CS0117: 'XamlResourceIdAttribute' does not contain a definition for 'GetPathForType'

D:\Projects\MyApp\WebInterface\MAUIApp\obj\Debug\net10.0-android\generated\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.XamlGenerator\App.xaml.xsg.cs(44,170): error CS0117: 'ResourceDictionary.RDSourceTypeConverter' does not contain a definition for 'GetResourcePath'

Could you please help me understand why this is happening and how to resolve it?

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 14,020 Reputation points Microsoft External Staff Moderator
    2026-02-18T06:56:17.9033333+00:00

    Hi @Bhuwan ,

    Thanks for reaching out.

    I looked at the errors you’re seeing with SourceGen in your MAUI project. The root cause here is that the generated code is trying to call methods like XamlResourceIdAttribute.GetPathForType and ResourceDictionary.RDSourceTypeConverter.GetResourcePath that aren’t available in the version of MAUI or the NuGet packages you currently have. Essentially, the “SourceGen robot” is asking for tools that aren’t in the toolbox yet.

    I would suggest a few ways:

    1. Update MAUI packages - Make sure all your Microsoft.Maui.* NuGet packages are up to date and matching versions. SourceGen depends on features present in the latest builds.
    2. Check your MAUI version - SourceGen works best with .NET MAUI 10 or later. Older versions can produce code referencing missing methods.
    3. Clean and rebuild - Delete bin and obj folders to remove stale generated files, then rebuild the project.
    4. Optional fallback - If updating is tricky, you can temporarily remove or comment out:
         <MauiXamlInflator>SourceGen</MauiXamlInflator>
         <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
      
      Your app will still work, just without the SourceGen optimizations.

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

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-18T05:48:56.9933333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The errors you are encountering after adding the <MauiXamlInflator>SourceGen</MauiXamlInflator> and <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> tags to your .csproj file suggest that there may be compatibility issues with the generated code and the definitions available in your project.

    The specific errors indicate that the XamlResourceIdAttribute and ResourceDictionary.RDSourceTypeConverter classes do not contain the expected methods (GetPathForType and GetResourcePath, respectively). This could be due to a few reasons:

    1. Version Compatibility: Ensure that you are using the correct version of .NET MAUI that supports the source generation features. The source generation capabilities may require a specific version of the SDK or libraries.
    2. NuGet Packages: Check if all the necessary NuGet packages are updated to their latest versions. Sometimes, older versions may not have the required definitions or methods.
    3. Clean and Rebuild: Try cleaning your project and rebuilding it. Sometimes, stale build artifacts can cause issues.
    4. Documentation Reference: Review the official documentation regarding XAML source generation to ensure that you have set everything up correctly. The recommended way to enable source generation is to set the MauiXamlInflator value to SourceGen in your project file, which you have done correctly.

    If the problem persists, consider checking for any open issues on the relevant GitHub repositories or forums related to .NET MAUI for similar problems and solutions.

    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.