Maui iOS UIApplication.Main() 抛出异常

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

我有一个 Xamarin.Forms 应用程序,我正在将其移植到 MAUI。 Android 版本运行良好且构建良好。 iOS 存在一个长期存在的问题,即 Program.Main(args) 会引发异常。在我们真正能够单步执行任何操作之前,iOS 设备上的看门狗会杀死该应用程序。

代码:

using MyMauiApp;
using ObjCRuntime;
using System.Diagnostics;
using UIKit;

namespace MyMaui
{
    public class Program
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            try
            {
                UIApplication.Main(args, null, typeof(AppDelegate));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("*-*-*-*-*-*-*-");
                Debug.WriteLine(ex);
                Debug.WriteLine("*-*-*-*-*-*-*-");
            }
        }
    }
}
[0:] *-*-*-*-*-*-*-
[0:] System.TypeLoadException: Could not resolve type with token 01000005 from typeref (expected class 'System.Runtime.CompilerServices.InternalsVisibleToAttribute' in assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51')
   at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type , Boolean )
   at Microsoft.Maui.Platform.ReflectionExtensions.GetCustomAttributesSafe(Assembly assembly, Type attrType)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Assembly[] assemblies, Assembly defaultRendererAssembly, Type[] attrTypes, InitializationFlags flags, Action`1 viewRegistered, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Type[] attrTypes, InitializationFlags flags, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Type[] attrTypes, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Compatibility.Forms.RegisterCompatRenderers(IMauiContext )
   at Microsoft.Maui.Controls.Compatibility.Forms.SetupInit(IMauiContext , Nullable`1 )
   at Microsoft.Maui.Controls.Compatibility.Forms.Init(IActivationState , Nullable`1 )
   at Microsoft.Maui.Controls.Compatibility.Hosting.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__1_1(IMauiContext mauiContext)
   at Microsoft.Maui.Platform.ApplicationExtensions.<>c__DisplayClass3_0.<CreatePlatformWindow>b__0(OnMauiContextCreated del)
   at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnMauiContextCreated](IServiceProvider services, Action`1 action)
   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 MauiSalesSupportApp.AppDelegate.FinishedLaunching(UIApplication app, NSDictionary options) in C:\Users\myUser\Documents\Source-Repos\myRepo\mySolution\Platforms\iOS\AppDelegate.cs:line 70
   at UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr ) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] , Type , Type ) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at myApp.Program.Main(String[] args) in C:\Users\myUser\Documents\Source-Repos\myRepo\myApp\Platforms\iOS\Program.cs:line 17
[0:] *-*-*-*-*-*-*-

我们尝试清理和重建该项目。

我正在使用.NET 8.0.303。 iOS 版本是 17.5.1。 软件包包括:ACR.UserDialogs (9.0.0)、CommunityToolkit.Maui (9.0.2)、CommunityToolkit.Mvvm (8.2.2)、FFImageLoading.Maui (1.2.6)、Microsoft.AppCenter (5.0.5)、Microsoft。 AppCenter.Crashes (5.0.5)、Microsoft.AppCenter.Analystic (5.0.5)、Microsoft.Maui.Controls (8.0.70)、Microsoft.Maui.Controls.Compatibility (8.0.70)、Microsoft.Maui.Controls.Maps (8.0.70)、Microsoft.NET.ILLink.Tasks (8.0.7)、MonkeyCache.SQLite(2.1) .1)、Newtonsoft.JSON(13.0.3)、Prism.Core (9.0.462)、Prism.DryIoc.Maui (9.0.462)、Prism.Maui (9.0.462)、Prism.Maui.Rx (9.0.462)、SkiaSharp (2.88.8)、Syncfusion.Licensing (26.1.42)、Syncfusion.Maui.Calendar (26.1. 42)、Syncfusion.Maui.Core (26.1.42), Syncfusion.Maui.Inputs (26.1.42)、Syncfusion.Maui.Popup (26.1.42)、Syncfusion.Maui.TabView (26.1.42)、Xam.Plugin.DeviceInfo (4.2.0)、ZXing.Net.Maui ( 0.4.0), ZXing.Net.Maui.Controls (0.4.0).

ios uikit maui
1个回答
0
投票

作为快速诊断步骤,请在从 Visual Studio 部署应用程序后尝试从 iPhone 启动该应用程序。当我这样做时,应用程序运行良好,但如果我尝试从 Visual Studio 进行调试,则会崩溃,这表明附加 VS 时出现问题。

我能够通过禁用热重载来解决这个问题:

  1. 在 Visual Studio 中,转到“工具”->“选项”
  2. 展开调试
  3. 选择XAML热重载
  4. 取消选中 Android 和 iOS (.NET MAUI) enter image description here
  5. 单击“确定”以应用选项弹出窗口中的更改

这很烦人,因为如果您正在开发 Android 项目,这也会禁用那里的热重载,但至少它使您能够在 iOS 上调试代码。

© www.soinside.com 2019 - 2024. All rights reserved.