.NET MAUI app: The type 'maui:MauiWinUIApplication' was not found. Unable to build the .NET MAUI app

1.2k views Asked by At

I have a problem with building a .NET MAUI app. When I build the app I get this error message:

Severity Code Description Project File Line Suppression State Error XLS0414 The type 'maui:MauiWinUIApplication' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

Screenshot: 'maui:MauiWinUIApplication' was not found

And this one:

Severity Code Description Project File Line Suppression State Error CS1061 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?) Qit.QtimeUniversal.MAUI (net7.0-windows10.0.22621.0)*

The problem is in the App.xaml (and App.xaml.cs) file of the Windows platform which is in the Targets/.../Platforms/Windows folder:

Screenshot: App.xaml

I also get this error:

*Severity Code Description Project File Line Suppression State Error WMC9999 Data at the root level is invalid. Line 1, position 2.

MSB4018 The "XamlCTask" task failed unexpectedly. System.Xml.XmlException: Data at the root level is invalid. Line 1, position 2.

in this file:

.....nuget\packages\microsoft.windowsappsdk\1.2.221209.1\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets file:

I saw a similar issue described here:

https://stackoverflow.com/questions/77335022/the-type-or-namespace-name-mauiwinuiapplication-does-not-exist-in-the-namespac

What I have tried so far:

  • I have deleted all the bin and obj folder of all projects in the solution and then rebuild the solution. But this didn't solve it.
  • I have checked if the .csproj file of the project the app.xaml.cs file is in is corrupted. But I could not find anything.
  • The build action of the app.xaml file is set to MauiXaml. I have changed this to build action: page , but this was not right and didn't solve it. The build action is by default: MauiXaml if you create a new .NET MAUI app project in Visual Studio.

It might have something to do with a reference assembly which is not right. But it used to work fine and now all for a sudden it failed to build. Does anybody have an idea what might be the root cause of these issues?

2

There are 2 answers

0
r-m85 On

I think I found the answer here: https://github.com/dotnet/maui/issues/5785

I've seen this a couple of times and I think that is something that needs to be improved in Visual Studio. Notice in the top-right corner there is a dropdown that now says VisualLogger (net6.0-android) that means your editor now shows the code as it would be compiled on Android. Hence, it won't find the Windows specific stuff.

Switch that dropdown to Windows and it should show fine.

Screenshot

This solved this issue:

Severity Code Description Project File Line Suppression State Error XLS0414 The type 'maui:MauiWinUIApplication' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. Qit.QtimeUniversal.MAUI C:\Dev\QIT\QFS\QtimeMobileMAUI\Qit.QtimeUniversalSolution\Qit.QtimeUniversalSolution\Platforms\Windows\App.xaml 1

Now I can build the app again on Windows. On android I still get a build error though.

0
MarkE On

I renamed my Maui project from AppNameA to AppNameB. After some manual namespace renaming and using the "Sync Namespaces" function in VS, I found that the file below had the WinUI part of its namespace renamed, and that was causing the "the type 'maui:MauiWinUIApplication' was not found." error.

File:

Platforms\Windows\App.xaml.cs

Old Namespace:

namespace AppNameA.WinUI

New Namespace needs to be:

namespace AppNameB.WinUI