System.ArgumentNullException:MvxWeakEventSubscription中缺少源事件信息

时间:2013-11-18 08:37:51

标签: xamarin.ios mvvmcross

我们正在使用MvvmCross(Hot Tuna版本)在我们的Xamarin.IOS项目中使用数据绑定,如示例应用程序“N-39-CrossLight-Touch”中所指定。

示例应用程序以及我们的项目在模拟器(IOS7)上运行良好,但在设备(IOS7)上,它会在绑定时抛出以下异常。

  

System.ArgumentNullException:缺少源事件信息   MvxWeakEventSubscription参数名称:sourceEventInfo at   Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2 [System.ComponentModel.INotifyPropertyChanged,System.ComponentModel.PropertyChangedEventArgs] ..构造函数   (INotifyPropertyChanged source,System.Reflection.EventInfo   sourceEventInfo,System.EventHandler1 targetEventHandler)[0x00000] in   :0点   Cirrious.CrossCore.WeakSubscription.MvxNotifyPropertyChangedEventSubscription..ctor   (INotifyPropertyChanged源,System.EventHandler1   targetEventHandler)[0x00000] in:0 at   Cirrious.CrossCore.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe   (INotifyPropertyChanged source,System.EventHandler1 eventHandler)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.MvxPropertyInfoSourceBinding..ctor   (System.Object source,System.Reflection.PropertyInfo propertyInfo)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxLeafPropertyInfoSourceBinding..ctor   (System.Object source,System.Reflection.PropertyInfo propertyInfo)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxSimpleLeafPropertyInfoSourceBinding..ctor   (System.Object source,System.Reflection.PropertyInfo propertyInfo)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxPropertySourceBindingFactoryExtension.CreateLeafBinding   (System.Object源码,   Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyToken   propertyToken)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxPropertySourceBindingFactoryExtension.TryCreateBinding   (System.Object源码,   Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyToken   currentToken,System.Collections.Generic.List1 remainingTokens,   IMvxSourceBinding&安培;结果)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxSourceBindingFactory.TryCreateBindingFromExtensions   (System.Object源码,   Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyToken   propertyToken,System.Collections.Generic.List1 remainingTokens,   IMvxSourceBinding&安培;结果)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxSourceBindingFactory.CreateBinding   (System.Object source,IList1 tokens)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxSourceBindingFactory.CreateBinding   (System.Object source,System.String combinedPropertyName)[0x00000]   in:0 at   Cirrious.MvvmCross.Binding.Bindings.SourceSteps.MvxPathSourceStep.OnDataContextChanged   ()[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.SourceSteps.MvxSourceStep.set_DataContext   (System.Object value)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.CreateSourceBinding   (System.Object source)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding..ctor   (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder.BindSingle   (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest)   [0x00000] in:0 at   Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder + LT;> C_ DisplayClass1.b _0   (Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription   描述)[0x00000] in:0 at   System.Linq.Enumerable + c__Iterator102 [Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription,Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding] .MoveNext   ()[0x00000] in:0 at   Cirrious.MvvmCross.Binding.BindingContext.MvxBindingContextOwnerExtensions.AddBindings   (IMvxBindingContextOwner视图,IEnumerable1绑定,System.Object   clearKey)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.BindingContext.MvxBindingContextOwnerExtensions.AddBindings   (IMvxBindingContextOwner视图,System.Object目标,IEnumerable1   bindingDescriptions,System.Object clearKey)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.BindingContext.MvxBindingContextOwnerExtensions.AddBinding   (IMvxBindingContextOwner视图,System.Object目标,   Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription   bindingDescription,System.Object clearKey)[0x00000] in:0 at   Cirrious.MvvmCross.Binding.BindingContext.MvxBaseFluentBindingDescription1 [MonoTouch.UIKit.UITextField]。适用   ()[0x00000] in:0 at   Cirrious.MvvmCross.Binding.BindingContext.MvxFluentBindingDescriptionSet2 [CrossLightTouch.MyViewController,CrossLightTouch.ViewModels.MyViewModel]。适用   ()[0x00000] in:0:CrossLightTouch.MyViewController.ViewDidLoad()   [0x0024f] in   /Users/admin/Downloads/N-39-CrossLight-Touch/CrossLightTouch/MyViewController.cs:81   at at(包装器管理到原生)   MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend(intptr,intptr)at at   MonoTouch.UIKit.UIWindow.MakeKeyAndVisible()[0x00008] in   /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129   在CrossLightTouch.AppDelegate.FinishedLaunching   (MonoTouch.UIKit.UIApplication应用程序,MonoTouch.Foundation.NSDictionary   选项)[0x00042] in   /Users/admin/Downloads/N-39-CrossLight-Touch/CrossLightTouch/AppDelegate.cs:25   at at(包装器管理到原生)   MonoTouch.UIKit.UIApplication:UIApplicationMain   (int,string [],intptr,intptr)在MonoTouch.UIKit.UIApplication.Main   (System.String [] args,System.String principalClassName,System.String   delegateClassName)[0x0004c] in   /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIApplication.cs:38   在CrossLightTouch.Application.Main(System.String [] args)[0x00008]   在   /Users/admin/Downloads/N-39-CrossLight-Touch/CrossLightTouch/Main.cs:17

通过设置IOS构建选项 - >链接行为 - >不要链接,它按预期在设备上工作,但二进制大小已加倍。

您可以使用“N-39-CrossLight-Touch”样本重现此问题。

是否有修复或替代方案?

1 个答案:

答案 0 :(得分:1)

如果您还没有LinkerPleaseInclude文件,请将此处的文件复制到您的项目中:

https://github.com/MvvmCross/MvvmCross/blob/6ab1baa9ca128921208efa994890039edf398474/TestProjects/Android-Support/Fragments/Example.Droid/LinkerPleaseInclude.cs

此外,将以下行添加到Include(TextView text)方法:

text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;

如果这还没有解决,请查找可能在Mvx绑定中使用的其他事件,并将其添加到LinkerPleaseInclude文件中。

此问题是由Android上Mvx绑定的动态特性引起的。由于绑定是在运行时解析的,因此Xamarin链接器认为它们引用的UI事件未被使用,因此它们将从最终构建中删除。在LinkerPleaseInclude文件中添加引用会强制它们被包含在内。