title | description | ms.date |
---|---|---|
Troubleshoot known issues |
Learn about .NET MAUI known issues and troubleshooting you can do to resolve these issues. |
10/02/2023 |
This article describes some of the known issues with .NET Multi-platform App UI (.NET MAUI), and how you can solve or work around them. The .NET MAUI repository also details some known issues.
There are two options for installing the .NET MAUI workloads:
- Visual Studio on Windows can install .msi files for each workload pack.
dotnet workload install
commands.
On Windows, if you run a dotnet workload install
after installing .NET MAUI through the Visual Studio installer, Visual Studio can enter a state where it can't locate the .NET MAUI workloads. You'll receive build errors telling you to install the .NET MAUI workloads, and it's possible to enter a state where the workloads can't be repaired or reinstalled. For more information, see the GitHub issue dotnet/sdk#22388.
The solution to this issue on Windows is to uninstall the .NET MAUI workloads through the CLI, uninstall any .NET SDKs in Control Panel, and uninstall the .NET MAUI workloads in Visual Studio. These uninstalls can be accomplished with the following process:
- Run
dotnet workload uninstall maui
if you ever used thedotnet workload install
commands. - Uninstall any standalone .NET SDK installers from Control Panel. These installers have names similar to
Microsoft .NET SDK 6.0.300
. - In every instance of Visual Studio, uninstall the .NET Multi-platform App UI development, and .NET desktop development Visual Studio workloads.
Then, check if there are additional .msi
files that need to be uninstalled by running the following command:
reg query HKLM\SOFTWARE\Microsoft\Windows\currentversion\uninstall\ -s -f manifest
This reg query
command lists .NET 6+ SDKs that are still installed on your machine, such as:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\currentversion\uninstall\{EEC1BB5F-3391-43C2-810E-42D78ADF3140}
InstallSource REG_SZ C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.MacCatalyst.Manifest-6.0.300,version=125.179.40883,chip=x64,productarch=neutral\
DisplayName REG_SZ Microsoft.NET.Sdk.MacCatalyst.Manifest-6.0.300
If you receive similar output, you should copy the GUID for each package and uninstall the package with the msiexec
command:
msiexec /x {EEC1BB5F-3391-43C2-810E-42D78ADF3140} /q IGNOREDEPENDENCIES=ALL
Then, you should keep executing the reg query
command until it doesn't return any results. Once there are no more results and all .NET 6+ SDKs are uninstalled, you should also consider deleting the following folders:
C:\Program Files\dotnet\sdk-manifests
C:\Program Files\dotnet\metadata
C:\Program Files\dotnet\packs
C:\Program Files\dotnet\library-packs
C:\Program Files\dotnet\template-packs
C:\Program Files\dotnet\sdk\6.*
orC:\Program Files\dotnet\sdk\7.*
C:\Program Files\dotnet\host\fxr\6.*
orC:\Program Files\dotnet\host\fxr\7.*
After following this process, you should be able to reinstall .NET MAUI either through Visual Studio, or by installing your chosen .NET SDK version and running the dotnet workload install maui
command.
Visual Studio for Mac's installer and updater uses dotnet workload install
commands to install the .NET MAUI .pkg files.
Since .pkg files can't be uninstalled, the simplest approach to uninstalling the workloads on a Mac is to run the following commands to delete the specified folders:
rm -r ~/.dotnet/
sudo rm -r /usr/local/share/dotnet/
After executing these commands, you should be able to reinstall .NET MAUI either through Visual Studio for Mac, or by installing your chosen .NET SDK version and running dotnet workload install maui
command.
Visual Studio may not be resolving the required workloads if you try to compile a project and receive an error similar to the following text:
Platform version is not present for one or more target frameworks, even though they have specified a platform: net8.0-android, net8.0-ios, net8.0-maccatalyst
This problem typically results from having an x86 and x64 SDK installed, and the x86 version is being used. Visual Studio and .NET MAUI require the x64 .NET SDK. If your operating system has a system-wide PATH
variable that is resolving the x86 SDK first, you need to fix that by either removing the x86 .NET SDK from the PATH
variable, or promoting the x64 .NET SDK so that it resolves first. For more information on troubleshooting x86 vs x64 SDK resolution, see Install .NET on Windows - Troubleshooting.
When using the Contacts
API, you may see the following error related to iOS and macOS:
The type or namespace name 'Default' does not exist in the namespace 'Contacts' (are you missing an assembly reference?)
The iOS and macOS platforms contain a root namespace named Contacts
. This conflict causes a conflict for those platforms with the Microsoft.Maui.ApplicationModel.Communication
namespace, which contains a Contacts
type. The Microsoft.Maui.ApplicationModel.Communication
namespace is automatically imported by the <ImplicitUsings>
setting in the project file.
To write code that also compiles for iOS and macOS, fully qualify the Contacts
type. Alternatively, provide a using
directive at the top of the code file to map the Communication
namespace:
using Communication = Microsoft.Maui.ApplicationModel.Communication;
// Code that uses the namespace:
var contact = await Communication.Contacts.Default.PickContactAsync();
After you install the Xcode command line tools using xcode-select --install
, Visual Studio for Mac might show a "Xcode is not currently installed or could not be found" message when you attempt to build .NET MAUI apps that target iOS or Mac Catalyst. In this scenario, check that you also have Xcode installed from the App Store. Then, launch Xcode and go to Xcode > Preferences > Locations > Command Line Tools and check if the drop-down is empty. If it's empty, select the drop-down, and then select the location of the Xcode command line tools. Then close Xcode and restart Visual Studio for Mac.
If you receive the error "Could not find a valid Xcode app bundle at '/Library/Developer/CommandLineTools'" when you attempt to build .NET MAUI apps that target iOS or Mac Catalyst, try the solution described in Xcode isn't currently installed or couldn't be found. If you're still unable to access the Xcode > Preferences > Locations > Command Line Tools drop-down, run the following command:
sudo xcode-select --reset
::: moniker range=">=net-maui-8.0"
xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView has built-in logging that can help you diagnose problems in your Blazor Hybrid app. There are two steps to enable this logging:
- Enable xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView and related components to log diagnostic information.
- Configure a logger to write the log output to where you can view it.
For more information, see Diagnosing issues in Blazor Hybrid apps.
For troubleshooting purposes, image resource packaging can be disabled by setting the $(EnableMauiImageProcessing)
build property to false
in the first <PropertyGroup>
node in your project file:
<EnableMauiImageProcessing>false</EnableMauiImageProcessing>
For troubleshooting purposes, splash screen resource generation can be disabled by setting the $(EnableSplashScreenProcessing)
build property to false
in the first <PropertyGroup>
node in your project file:
<EnableSplashScreenProcessing>false</EnableSplashScreenProcessing>
For troubleshooting purposes, font resource packaging can be disabled by setting the $(EnableMauiFontProcessing)
build property to false
in the first <PropertyGroup>
node in your project file:
<EnableMauiFontProcessing>false</EnableMauiFontProcessing>
For troubleshooting purposes, asset file resource packaging can be disabled by setting the $(EnableMauiAssetProcessing)
build property to false
in the first <PropertyGroup>
node in your project file:
<EnableMauiAssetProcessing>false</EnableMauiAssetProcessing>
For troubleshooting purposes, a blank splash screen can be generated if you don't have a <MauiSplashScreen>
item and you don't have a custom splash screen. This can be achieved by setting the $(EnableBlankMauiSplashScreen)
build property to true
in the first <PropertyGroup>
node in your project file:
<EnableBlankMauiSplashScreen>true</EnableBlankMauiSplashScreen>
Generating a blank splash screen will override any custom splash screen and will cause app store rejection. However, it can be a useful approach in testing to ensure that your app UI is correct.
You may encounter build errors about duplicate image filenames:
One or more duplicate file names were detected. All image output filenames must be unique.
This can occur for MauiIcon
and MauiImage
items. For example, the following MauiImage
items in an <ItemGroup>
node in your project file will result in this error:
<MauiImage Include="Resources\Images\*" />
<MauiImage Include="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
This occurs because from .NET 8, .NET MAUI checks to ensure that there are no duplicate image resource filenames.
If you receive this build error it can be fixed by ensuring that your project file doesn't include duplicate images. To do this, change any MauiIcon
or MauiImage
that references a specific file to use the Update
attribute instead of the Include
attribute:
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
For information about MSBuild item element attributes, see Item element (MSBuild): Attributes and elements.
::: moniker-end