我目前正在学习有关如何构建 ASP.NET blazor 应用程序的课程并且已经走到了死胡同。正如标题所述,方法 CreateMauiApp() 需要一个 void 返回类型。一个关键的区别是我正在学习一门 1 岁的课程,并且不包括我正在使用的毛伊岛。有没有人知道这个问题的解决方法?
public static class MauiProgram
{
public static async MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.RegisterBlazorMauiWebView()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
//builder.Services.AddSingleton<IUserManager, UserManager>();
//builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddSingleton<IUserManager, UserManagerFake>();
builder.Services.AddScoped<ICurrentUserService, CurrentUserService>();
builder.Services.AddBlazorWebView();
var host = builder.Build();
var currentUserService = host.Services.GetRequiredService<ICurrentUserService>();
TestData.CreateTestUser();
currentUserService.CurrentUser = TestData.TestUser;
await host.RunAsync();
}
}
}
错误信息:
错误 CS0161 'MauiProgram.CreateMauiApp()':并非所有代码路径都返回值 UdemyCourseIntro (net6.0-android)、UdemyCourseIntro (net6.0-ios)、UdemyCourseIntro (net6.0-maccatalyst)、UdemyCourseIntro (net6.0- windows10.0.19041) C:\Users\matej\source\repos\UdemyCourseIntro\UdemyCourseIntro\MauiProgram.cs 11 活动
错误 CS1983 异步方法的返回类型必须为 void、Task、Task、类似任务的类型、IAsyncEnumerable 或 IAsyncEnumerator UdemyCourseIntro (net6.0-android)、UdemyCourseIntro (net6.0-ios)、UdemyCourseIntro (net6.0 -maccatalyst), UdemyCourseIntro (net6.0-windows10.0.19041) C:\Users\matej\source\repos\UdemyCourseIntro\UdemyCourseIntro\MauiProgram.cs 11 活动