将 Xamarin Forms 迁移到毛伊岛,它可以在调试模式下工作,但不能在发布模式下工作?

问题描述 投票:0回答:1

我正在将 xamarin 表单迁移到 Maui 应用程序中,并且正在使用 Visual Studio Mac,我可以在调试模式下运行该应用程序,没有任何问题,但无法在发布模式下运行该应用程序。

我正在使用 Prism MVVM,并且我在 MauiProgram.cs 文件中创建了 CreateWindow

 .CreateWindow(async (container, navigation) =>
 {
     try
     {
         if (VersionTracking.IsFirstLaunchEver && !AppConstants.IsLoggedInUser && !Convert.ToBoolean(await SecureStorage.GetAsync(AppConstants.ShowBiometricConsent).ConfigureAwait(false)))
         {
             AppConstants.IsLoggedInUser = true;
             SecureStorage.RemoveAll();
             await SecureStorage.SetAsync(AppConstants.LoggedIn, AppConstants.False);
             await SecureStorage.SetAsync(AppConstants.LoggedOut, AppConstants.True);
             await SecureStorage.SetAsync(AppConstants.ShowBiometricConsent, AppConstants.True);
             await SecureStorage.SetAsync(AppConstants.ShowNotificationOptions, AppConstants.True);

             await Theme.SetTheme();

             await ClearLoginCredentials();

             await navigation.NavigateAsync(AppConstants.LoginPage);
         }
         else
         {
             await Theme.SetTheme().ConfigureAwait(false);

             var isLoggedOut = Convert.ToBoolean(await SecureStorage.GetAsync(AppConstants.LoggedOut).ConfigureAwait(false));

             if (isLoggedOut)
             {
                 await ClearLoginCredentials();
                 await SecureStorage.SetAsync(AppConstants.LoggedIn, AppConstants.False).ConfigureAwait(false);
                 await navigation.NavigateAsync(AppConstants.LoginPage).ConfigureAwait(false);
             }
             else
             {
                 await navigation.NavigateAsync(AppConstants.MainPage).ConfigureAwait(false);
             }
         }
         Profile.ProfileImage = null;
         Barrel.ApplicationId = Configurations.ClientID;
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
 });

一切都在调试模式下工作,但在发布模式下

[AppCenterXamarinCrashes] ERROR: +[MSACWrapperLogger MSACWrapperLog:tag:level:]/10 Unhandled Exception:
Microsoft.Maui.Controls.InvalidNavigationException: Expected Navigation Failed. No Root Window has been created.
   at Prism.Navigation.PrismWindowManager.CreateWindow(Application app, IActivationState activationState)
   at Microsoft.Maui.Controls.Application.CreateWindow(IActivationState activationState)
   at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
   at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
   at Jacobs.Platforms.AppDelegate.FinishedLaunching(UIApplication app, NSDictionary options)

如何解决这个问题?

maui prism xamarin-forms-4
1个回答
0
投票

如果您不在应用程序 (App.xaml.cs) 的构造函数中调用 InitializeComponent,则会引发此错误

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
    }
© www.soinside.com 2019 - 2024. All rights reserved.