我使用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.
}
这是一个默认代码,我刚刚更改了超类(UIViewController到MvxViewController)
无法找到类型为Cirrious.MvvmCross.ViewModels.MvxViewModelLoader的构造函数 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type type)[0x00000] in:0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer + ConstructingResolver.Resolve()[0x00000] in:0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve(System.Type类型,ResolveOptions resolveOptions,System.Object& resolved)[0x00000] in:0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve(System.Type type,System.Object& resolved)[0x00000] in:0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve(System.Type t)[0x00000] in:0 在Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve [IMvxViewModelLoader]()[0x00000] in:0 在Cirrious.CrossCore.Mvx.Resolve [IMvxViewModelLoader]()[0x00000] in:0 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel(IMvxTouchView touchView)[0x00000] in:0 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods +<> c_ DisplayClass1.b _0()[0x00000] in:0 在Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate(IMvxView视图,System.Func`1 viewModelLoader)[0x00000] in:0 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate(IMvxTouchView touchView)[0x00000] in:0 在Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled(System.Object sender,System.EventArgs e)[0x00000] in:0 at(wrapper delegate-invoke):invoke_void_ this __ object_EventArgs(object,System.EventArgs) 在Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise(System.EventHandler eventHandler,System.Object sender)[0x00000] in:0 在Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad()[0x00000] in:0 在/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Views/MainView.cs:30中的TrainingCatalog.Touch.MainView.ViewDidLoad()[0x00002] at(包装器托管到原生)MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend(intptr,intptr) 在/Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129中的MonoTouch.UIKit.UIWindow.MakeKeyAndVisible()[0x00008] 在TrainingCatalog.Touch.AppDelegate.FinishedLaunching(MonoTouch.UIKit.UIApplication应用程序,MonoTouch.Foundation.NSDictionary选项)[0x0003c]在/Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/AppDelegate.cs:21 at(包装器托管到原生)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.String principalClassName,System.String delegateClassName)[0x0004c]: 38 在TrainingCatalog.Touch.Application.Main(System.String [] args)[0x00008] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Main.cs:17
找不到类型Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
的构造函数
答案 0 :(得分:2)
从堆栈跟踪中,我猜测失败的行是: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>();
}
查看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追逐这个。