我有一个 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).