Share via

Issue to Initialize compoment

Peter Liang 3,286 Reputation points
2026-04-08T07:08:22.7366667+00:00

Hi,

How to resolve it below?

圖片

Developer technologies | ASP.NET | Other

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 16,115 Reputation points Microsoft External Staff Moderator
    2026-04-08T08:28:12.6733333+00:00

    Hi @Peter Liang ,

    Thanks for reaching out.

    From the screenshot, this looks like a .NET MAUI app rather than an ASP.NET app. The key clues are the App : Application class, the CreateWindow(...) override, and the project target showing something like net10.0-android. In MAUI, InitializeComponent() is generated from the matching XAML file, so this error usually means that link was not created correctly.

    To resolve it, please check the following:

    1. Make sure you have an App.xaml file in the project.
    2. In App.xaml, confirm that the x:Class value exactly matches the namespace and class name in App.xaml.cs. For example, if your code-behind is namespace MauiApp10; public partial class App : Application, then App.xaml should have:   xml   x:Class="MauiApp10.App"   
    3. Make sure App.xaml.cs is declared as partial.
    4. Verify that the build action for App.xaml is set to MauiXaml.
    5. Clean the solution, delete the bin and obj folders, then rebuild the project.

    If your project is truly ASP.NET or ASP.NET Core, then this App.xaml.cs / InitializeComponent() pattern does not belong there, and the application should instead be configured through Program.cs. In that case, the fix would be to remove this MAUI/XAML-based code from the web project.

    Based on the screenshot though, the most likely fix is to restore or correct the App.xaml to App.xaml.cs mapping, then rebuild.

    Hope this helps! If my answer was helpful, I would greatly appreciate it if you could 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-04-08T07:08:38.1666667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error occurs because InitializeComponent() is not defined for the App class in the generated partial class, so the compiler cannot find that method name in the current context.

    InitializeComponent() is a method generated by the XAML build for UI components (for example, windows, pages, or controls) that implement System.Windows.Markup.IComponentConnector. In the referenced APIs, InitializeComponent() is exposed on WPF-related classes such as ErrorWindow and SessionOverview:

    public void InitializeComponent();
    

    If the class does not have a generated XAML partial with that method, calling InitializeComponent() will fail with exactly the error shown.

    To resolve the issue:

    1. Remove the InitializeComponent(); call from the App constructor if App.xaml is not meant to have generated UI initialization.
    2. Or, if App is supposed to have XAML-generated content, ensure that:
      • There is a corresponding App.xaml file with x:Class matching the namespace and class name of App.
      • The project builds XAML correctly so that the partial class containing InitializeComponent() is generated.

    In most .NET MAUI templates, the App class does not call InitializeComponent(); only visual elements like MainPage, AppShell, or other XAML pages do. Keeping App as a simple class that sets MainPage (or returns a Window in CreateWindow) without InitializeComponent() is the typical fix.


    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.