.Net MAUI 应用程序未在 IOS 上启动:NullReferenceException。在公共应用程序()中

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

我的 MAUI .Net 应用程序在启动时崩溃。

我有 System.NullReferenceException

开:

public App()

致电者:

 UIApplication.Main(args, null, typeof(AppDelegate));

堆栈跟踪:

at ObjCRuntime.Class.ResolveFullTokenReference(UInt32 token_reference) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 422
   at ObjCRuntime.Class.ResolveTokenReference(UInt32 token_reference, UInt32 implicit_token_type) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 463
   at ObjCRuntime.Class.ResolveMethodTokenReference(UInt32 token_reference) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 449
   at ObjCRuntime.Runtime.GetMethodFromToken(UInt32 token_ref) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 820
   at Foundation.NSObject.InvokeOnMainThread(Action action) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:line 782
   at Microsoft.Maui.ApplicationModel.MainThread.InvokeOnMainThread[UITraitCollection](Func`1 factory)
   at Microsoft.Maui.ApplicationModel.AppInfoImplementation.get_RequestedTheme()
   at Microsoft.Maui.ApplicationModel.AppInfo.get_RequestedTheme()
   at Microsoft.Maui.Controls.Application..ctor(Boolean setCurrentApplication)
   at Microsoft.Maui.Controls.Application..ctor()
   at MauiApp2.App..ctor() in C:\Users\samuelcarrier\source\repos\MauiApp2\MauiApp2\App.xaml.cs:line 5
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
   at System.Collections.Concurrent.ConcurrentDictionary`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.Extensions.DependencyInjection.ServiceProvider.ServiceAccessor, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].GetOrAdd(ServiceIdentifier key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider provider)
   at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at MauiApp2.Program.Main(String[] args) in C:\Users\samuelcarrier\source\repos\MauiApp2\MauiApp2\Platforms\iOS\Program.cs:line 14

如何调试以找到问题根源?

visual-studio ios-simulator maui .net-8.0
1个回答
0
投票

希望您的问题得到解决。如果没有,请尝试删除 bin 和 obj 文件夹并尝试。我刚刚得到同样的错误。删除 bin 和 obj 文件夹后,当我与我的 Mac 配对并尝试在 IOS 模拟器中运行该应用程序时,它运行良好。

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