Search code examples
c#iosmaui

The type or namespace name 'MauiWinUIApplication' does not exist in the namespace 'Microsoft.Maui'


I installed the latest release of Visual Studio 2022, Version - 17.7.5. Since doing that I cannot get past this error when trying to compile. The error is this;

error CS0234: The type or namespace name 'MauiWinUIApplication' does not exist in the namespace 'Microsoft.Maui' (are you missing an assembly reference?)

This is my first Maui app, and has been going good so far, but cannot get past this error. In my project file, I have the 2 Mac related frameworks included so nothing special there;

<TargetFrameworks>net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks) 

The message is referring to Win in the file name which I assume is windows, but have not added any code to the windows folder and it is not even defined as a framework I am working with.

My project structure is as follows, keeping in mind that I have not added anything under any of the other folders but the iOS one in this structure.

e

I almost forgot to mention, the project built and ran in the simulator without issue for months before this happened, but now issues.

Any help would be greatly appreciated... Thanks!


Solution

  • I had a similar issue and 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

    If you do this you should be able to build your solution without excluding the windows target.