我使用MvvmCross开发CrossPlatform应用程序。我在Mac上工作,构建解决方案时没有错误。当我运行它时...我遇到此错误:未能找到类型Cirrious.MvvmCross.ViewModels.MvxViewModelLoader的构造函数,并突出显示base.ViewDidLoad();。代码:public partial class MainView : MvxViewController{ static bool UserInterfaceIdiomIsPhone { get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; } } public MainView () : base (UserInterfaceIdiomIsPhone ? "MainView_iPhone" : "MainView_iPad", null) { } public override void DidReceiveMemoryWarning () { // Releases the view if it doesn't have a superview. base.DidReceiveMemoryWarning (); // Release any cached data, images, etc that aren't in use. } public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. }这是默认代码,我刚刚将 super class (UIViewController更改为MvxViewController)堆栈跟踪 : 找不到类型为Cirrious.MvvmCross.ViewModels.MvxViewModelLoader的构造函数 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type type)[0x00000]中的位置:: 0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer + ConstructingResolver.Resolve()[0x00000]中的位置: 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve(System.Type类型,ResolveOptions resolveOptions,System.Object和已解决)中:[0x00000],在:0中 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve(System.Type类型,System.Object已解析)中的[0x00000],在:0中 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve(System.Type t)[0x00000] in:0中 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve [IMvxViewModelLoader]()[0x00000]在:0中 在Cirrious.CrossCore.Mvx.Resolve [IMvxViewModelLoader]()[0x00000]中的位置:: 0 在0的Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel(IMvxTouchView touchView)[0x00000]中 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods + c_DisplayClass1.b_0()[0x00000]在:0中 在Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate(IMvxView视图,System.Func`1 viewModelLoader)中[0x00000]在:0中 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate(IMvxTouchView touchView)[0x00000]中:0 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled(System.Object发件人,System.EventArgs e)中:[0x00000],位于:0中 在(包装委托调用):invoke_void_this__object_EventArgs(object,System.EventArgs) 在Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise(System.EventHandler eventHandler,System.Object sender)中[0x00000]在:0中 在Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad()[0x00000]中的位置:: 0 在/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Views/MainView.cs:30中的TrainingCatalog.Touch.MainView.ViewDidLoad()[0x00002] 在(包装器托管到本地)MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend(intptr,intptr) 在/Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129中的MonoTouch.UIKit.UIWindow.MakeKeyAndVisible()[0x00008] 在/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/AppDelegate.cs:21中的/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/MonoTouch.UIKit.UIApplication应用程序,MonoTouch.Foundation.NSDictionary选项中的[0x0003c] 在(包装器托管到本地)MonoTouch.UIKit.UIApplication:UIApplicationMain(int,string [],intptr,intptr) 在/Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIApplication.cs中的MonoTouch.UIKit.UIApplication.Main(System.String [] args,System.StringPrincipalClassName,System.String委托ClassName)[0x0004c]处: 38 在/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Main.cs:17中的TrainingCatalog.Touch.Application.Main(System.String [] args)[0x00008] 找不到类型为Cirrious.MvvmCross.ViewModels.MvxViewModelLoader的构造函数 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 从堆栈跟踪中,我猜测失败的行是:https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxViewControllerExtensionMethods.cs#L44这是在IoC中寻找已在安装程序中注册为的类型: protected virtual void InitializeViewModelFramework() { Mvx.RegisterType<IMvxViewModelLoader, MvxViewModelLoader>(); }(来自https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/Platform/MvxSetup.cs#L192)查看MvxViewModelLoader,它是在https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelLoader.cs中定义的-因此它应具有由编译器添加的默认public无参数构造函数...考虑到这一点...我猜想Xamarin可能正在从您部署的二进制文件中删除构造函数。这可能是由于您的链接器设置-因此,请检查是否已将链接器设置为链接“仅SDK”。但是,如果这样做没有帮助,则可能取决于Xamarin的某些优化/功能-因此您可能需要这样做。作为一种简单的解决方法,您可以尝试覆盖安装程序,以便使用: protected override void InitializeViewModelFramework() { Mvx.RegisterSingleton<IMvxViewModelLoader>(() => new MvxViewModelLoader>()); }但是,即使这行得通,我也担心链接器可能会剥夺您应用程序中的其他符号-因此,这可能还不够……您可能需要使用Xamarin来解决。 (adsbygoogle = window.adsbygoogle || []).push({}); 10-08 11:44