Reputation: 196
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:
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:
What I have tried so far:
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?
Upvotes: 2
Views: 8256
Reputation: 19
Run dotnet workload update
, then remove the publish profile and re-create it.
Upvotes: 0
Reputation: 574
In my scenario it was incorrect .csproj
configuration of my MAUI app. In .net MAUI
you cannot reference <PackageReference>
or projects that are not compatible with .net MAUI.
.
Also the issue can arise if you'd add:
net8.0;
to the <TargetFrameworks>
Upvotes: 1
Reputation: 196
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.
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.
Upvotes: 7
Reputation: 41
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
Upvotes: 2