Share via

WPF: CS0102 duplicate definitions - Both HomeView.g.cs and .g.i.cs being compiled

Shreyans Yadav 40 Reputation points
2026-02-12T19:16:39.5+00:00

Dear Community Members,

I am Shreyans Yadav, currently working on a WPF project.

During a coding session, I encountered an unforeseen error that I have experienced for the first time.

(Details below about the error)

I consulted multiple AI assistants, which suggested issues with duplicates (which I don't have) and bin file folders. They mentioned that HomeView.g.cs and HomeView.g.i.cs might be interfering with the compiler, or that the target framework version (net10.0) could be the issue.

I have tried everything I could. Please help me out.

Error Details:

CS0102: The type 'HomeView' already contains a definition for 'ChatBox'

CS0102: The type 'HomeView' already contains a definition for 'ChatMessagesPanel'

CS0102: The type 'HomeView' already contains a definition for 'ChatInputTextBox'

CS8646: 'IComponentConnector.Connect(int, object)' is explicitly implemented more than once

CS0102: The type 'HomeView' already contains a definition for '_contentLoaded'

CS0111: Type 'HomeView' already defines a member called 'InitializeComponent' with the same parameter types

CS0111: Type 'HomeView' already defines a member called 'System.Windows.Markup.IComponentConnector.Connect' with the same parameter types

Disclaimer:

  • I have NO duplicates in my entire solution for HomeView
  • I can only do messages via Teams App for screenshots and other details.

Current Situation:

Project: ModernBankingUIApp

Target Framework: net10.0-windows

File: HomeView.xaml in MVVM\View folder

Generated Files Found in obj\Debug\net10.0-windows\ folder:

DiscoveryView.g.cs (6 KB) - Modified: 12-02-2026 15:58

DiscoveryView.g.i.cs (6 KB) - Modified: 12-02-2026 15:58

HomeView.g.cs (6 KB) - Modified: 12-02-2026 15:58

HomeView.g.i.cs (6 KB) - Modified: 12-02-2026 15:58

SettingView.g.cs (4 KB) - Modified: 12-02-2026 15:58

SettingView.g.i.cs (4 KB) - Modified: 12-02-2026 15:58

Problem:

Both HomeView.g.cs AND HomeView.g.i.cs are being compiled together, causing duplicate member definitions for all auto-generated WPF members (x:Name fields, InitializeComponent method, IComponentConnector interface implementation, and _contentLoaded field). ---> This question might not be the cause of the problem if you notice something else please message me.

What I've Already Tried:

Deleted bin and obj folders multiple times

Cleaned and rebuilt solution

Recreated the HomeView.xaml file from scratch

Verified no duplicate x:Name attributes in XAML (each appears only once)

Verified correct partial class declaration in code-behind

Deleted .vs folder and rebuilt

Question:

How do I resolve this build conflict where both .g.cs and .g.i.cs generated files are being compiled simultaneously, causing duplicate definitions for all auto-generated WPF code?

Specific Questions:

  1. Is net10.0-windows a valid target framework, or should I downgrade to net8.0-windows?
  2. Why would both .g.cs and .g.i.cs be compiled together instead of just .g.cs?
  3. Is there a MSBuild flag or project setting that could be causing this?
  4. Has anyone encountered this with Visual Studio 2026 and the latest .NET SDK?

    Additional Information:

More Specific Questions:

Is net10.0-windows a valid target framework, or should I downgrade to net8.0-windows?

Why would both .g.cs and .g.i.cs be compiled together instead of just .g.cs?

Is there a MSBuild flag or project setting that could be causing this?

Has anyone encountered this with Visual Studio 2026 and the latest .NET SDK?

Additional Information:

For more details about my project, check out my GitHub repository: https://github.com/ShreyansYadav/ModernBankingUIApp

<PII removed>

Thank you for your assistance!

Developer technologies | Windows Presentation Foundation

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 16,115 Reputation points Microsoft External Staff Moderator
    2026-02-13T06:30:18.9266667+00:00

    Hi @Shreyans Yadav ,

    Thanks for reaching out.

    Is net10.0-windows a valid target framework, or should I downgrade to net8.0-windows?

    .NET 10 is supported for WPF. You can try downgrading to .NET 8 temporarily to see if the issue is related to .NET 10, but it’s not required.

    Is there a MSBuild flag or project setting that could be causing this?

    I looked at your repository, and I don’t see any explicit flag or project setting that would directly cause both .g.cs and .g.i.cs to be compiled.

    I suspect the issue could be caused by one of these scenarios:

    • Visual Studio’s design-time builds for IntelliSense sometimes don’t fully separate intermediate files from the final compilation, which can leave both .g.cs and .g.i.cs in the compile list.
    • MSBuild caches build state for performance. Even after cleaning bin/obj, corrupted cache data can persist. The MSBuild incremental builds documentation explains how file lists are cached.
    • Certain WPF build targets may add generated files to compilation in a way that bypasses normal exclusion logic, especially if custom targets are used or run at the wrong point in the build pipeline.

    You could try a more aggressive method to remove the generated files from the compile list: 

    <Target Name="RemoveIntermediateGeneratedFiles" AfterTargets="MarkupCompilePass1;MarkupCompilePass2" BeforeTargets="CoreCompile">
      <ItemGroup>
        <Compile Remove="**\*.g.i.cs" />
        <FileWrites Remove="**\*.g.i.cs" />
      </ItemGroup>
      <Message Text="Removed intermediate .g.i.cs files from compilation" Importance="high" />
    </Target>
    

    After adding this, make sure to fully clean your solution (delete bin and obj folders) and rebuild, ensures any cached intermediate state is cleared and prevents duplicate definitions from being compiled.

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


1 additional answer

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

    To resolve the build conflict where both HomeView.g.cs and HomeView.g.i.cs are being compiled simultaneously, causing duplicate definitions, consider the following steps:

    1. Check for Duplicate References: Ensure that there are no duplicate references in your project that might be causing the compiler to generate both files. Sometimes, a reference to the same assembly from different locations can lead to such issues.
    2. Clean and Rebuild: Since you've already tried deleting the bin and obj folders and cleaning the solution, ensure that you perform a full rebuild after cleaning. This can sometimes resolve issues with stale files.
    3. Review Project File: Open your .csproj file and check for any unusual settings or configurations that might lead to both files being generated. Look for any custom build actions or targets that might be affecting the compilation process.
    4. Target Framework: The net10.0-windows framework is valid, but if you suspect compatibility issues, you might want to try downgrading to net8.0-windows to see if it resolves the problem. However, ensure that all your dependencies support the target framework you choose.
    5. MSBuild Properties: Investigate if there are any MSBuild properties or flags that might be causing this behavior. You can check the build output for any warnings or messages that might indicate misconfigurations.
    6. Visual Studio Updates: Ensure that you are using the latest version of Visual Studio and the .NET SDK. Sometimes, bugs in the IDE or SDK can lead to unexpected behavior.
    7. Check XAML and Code-Behind: As you've already verified the XAML for duplicate x:Name attributes and checked the partial class declaration, ensure that there are no other files in your project that might inadvertently define members with the same names.

    If the problem persists, consider creating a minimal reproducible example and sharing it with the community for further assistance. This can help others identify the issue more effectively.


    References:

    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.