I am using .NET Maui and suddenly got an error with the error code CS0246 in the File MauiProgram.cs. The code of the file is:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
Builder
. UseMauiApp<App>()
. ConfigureFonts(fonts =>
{
Fonts. AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Fonts. AddFont("OpenSans Semibold.ttf", "OpenSansSemibold");
});
return builder. Build();
}
}
The error is displayed as following:
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) itsl (net6.0-maccatalyst), itsl (net6.0-windows10.0.22621.0) A:\VS\itsl\itsl\MauiProgram.cs 9 Active
I've already cleaned up the solution and restarted Visual Studio, but unfortunately nothing helped.
What can I do?
CodePudding user response:
App
is the class defined in App.xaml
. By default it should be in the same namespace as MauiProgram
, but if you have manually changed a namespace you may need to add a using
statement