'App' does not implement inherited abstract member 'MauiWinUIApplication.CreateMauiApp()'

Sam Wheat 361 Reputation points
2022-05-17T13:10:56.937+00:00

Error CS0534 'App' does not implement inherited abstract member 'MauiWinUIApplication.CreateMauiApp()' MyProject (net6.0-android) C:\Git\MyProject\obj\Debug\net6.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs 40 Active

AFAIK I have done nothing to change any android config items. I am trying to write a windows desktop app.

I created a new Maui project (it builds/runs fine) and compared the files and they appear to be identical other than project names.
There is no App.xaml in Platforms/Android in my project or the new app I created for comparison.
App.xaml.cs in Platforms/Windows does implement the abstract method:

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();  

How can I resolve this?

Visual Studio Info:

Microsoft Visual Studio Community 2022
Version 17.3.0 Preview 1.0
VisualStudio.17.Preview/17.3.0-pre.1.0+32505.426
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

.NET Core Debugging with WSL 1.0
.NET Core Debugging with WSL

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 2019 17.3.122.33185
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0 17.3.122.33185
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.3.122.33185
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.3.0-1.22254.1+9919d7e7bd753404a5d2328e5e3fb2de635169f3
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.22115.6
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.3.7 (c1ffb2a)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Django support 17.0.22115.6
Provides templates and integration for the Django web framework.

Python - Profiling support 17.0.22115.6
Profiling support for Python projects.

Python with Pylance 17.0.22115.6
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.0.0.2222701+751db1ebea5e6a9ecc7fa57fe447180422afa610
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62204.01010
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.10420.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.3.0-1.22254.1+9919d7e7bd753404a5d2328e5e3fb2de635169f3
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22178.3+6da0245a7ce4bb8483b8d1f2993c8ecaea967ad9
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin 17.3.0.91 (main@7802af5)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.3.0.30 (remotes/origin/main@fb6442dc1)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.2.15 (2e3b60e)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 12.3.99.58 (main/64b22fc)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: adf1bc4
Java.Interop: xamarin/java.interop/release/6.0.3xx@2a882d2d
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.38.2@7b1e016
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@fc3c2ac

Xamarin.iOS and Xamarin.Mac SDK 15.11.0.87 (406f3098e)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

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

Accepted answer
  1. Michael Taylor 48,281 Reputation points
    2022-05-17T19:09:58.313+00:00

    I see the issue now. It appears that you originally created the project as LeaderPivot.XAML.MAUI.Host.WinUI. That means the namespace used to generate the code was the same. However you later started changing the classes to be in the LeaderAnalytics.LeaderPivot... namespace. So the generated code, which is using the original namespace, is not being merged into your partial classes you've defined and hence you're getting the errors. You need to sync up your namespaces of your types to what your XAML files are using.

    From what I can tell you should make at least the following changes:

    • platforms\windows\app.xaml change the x:class and xmlns:local attributes to use the updated namespace name.
    • platforms\windows\app.xaml change 'maui:MauiWinUIApplicationto justApplication`.
    • AppShell.xaml make the same changes.

    Now the auto-generated files (*.g.cs) should correctly merge with your codebehind files.

    1 person found this answer helpful.
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Michael Taylor 48,281 Reputation points
    2022-05-17T14:31:42.277+00:00

    The error is coming from the auto-generated file. You didn't happen to check these auto-generated files into your repo did you? Clean the solution and ensure the entire bin\debug directory is wiped. Ensure none of these files were accidentally checked into your repo. Then rebuild.


  2. Sam Wheat 361 Reputation points
    2022-05-17T19:18:01.443+00:00

    Create a new project in VS in a temp dir, call it MauiApp1 exactly as shown here.
    Ensure the project builds and runs
    Open Platforms/Windows/App.xaml

    Note the WinUI namespace:

    <maui:MauiWinUIApplication
        x:Class="MauiApp1.WinUI.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:maui="using:Microsoft.Maui"
        xmlns:local="using:MauiApp1.WinUI">
    
    </maui:MauiWinUIApplication>
    

  3. Sam Wheat 361 Reputation points
    2022-05-17T15:20:22.943+00:00

    I have done nothing (intentionally) to configure multi-targeting. I only want to run on windows. If it works on Android I wont complain.

    Here is Platforms/Windows/App.xaml.cs

    public partial class App : MauiWinUIApplication
    {
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
        }
    
        protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
    }
    

    Project:

    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
            <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
            <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
            <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
            <OutputType>Exe</OutputType>
            <RootNamespace>MyProject</RootNamespace>
            <UseMaui>true</UseMaui>
            <SingleProject>true</SingleProject>
            <ImplicitUsings>enable</ImplicitUsings>
    
            <!-- Display name -->
            <ApplicationTitle>MyProject</ApplicationTitle>
    
            <!-- App Identifier -->
            <ApplicationId>MyProject</ApplicationId>
            <ApplicationIdGuid>B981403E-C786-4560-B56F-A286A88</ApplicationIdGuid>
    
            <!-- Versions -->
            <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
            <ApplicationVersion>1</ApplicationVersion>
    
            <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
            <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
            <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
            <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
            <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
            <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
        </PropertyGroup>
    
        <ItemGroup>
            <!-- App Icon -->
            <MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
    
            <!-- Splash Screen -->
            <MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" BaseSize="128,128" />
    
            <!-- Images -->
            <MauiImage Include="Resources\Images\*" />
            <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
    
            <!-- Custom Fonts -->
            <MauiFont Include="Resources\Fonts\*" />
    
            <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
            <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
        </ItemGroup>
    
    </Project>
    

  4. Sam Wheat 361 Reputation points
    2022-05-17T18:38:41.92+00:00

    Same problem.

    Please see this repo:

    https://github.com/leaderanalytics/LeaderPivot.XAML.MAUI.git

    I am only trying to build .Host project. The library project will not build and is not referenced from .Host.

    0 comments No comments