【问题标题】:System.ArgumentNullException: missing source event info in MvxWeakEventSubscriptionSystem.ArgumentNullException:MvxWeakEventSubscription 中缺少源事件信息
【发布时间】:2013-12-01 08:08:55
【问题描述】:

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

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

System.ArgumentNullException:缺少源事件信息 MvxWeakEventSubscription 参数名称:sourceEventInfo at Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2[System.ComponentModel.INotifyPropertyChanged,System.ComponentModel.PropertyChangedEventArgs]..ctor (INotifyPropertyChanged 源,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 源,System.EventHandler1 eventHandler) [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Bindings.Source.MvxPropertyInfoSourceBinding..ctor (System.Object 源,System.Reflection.PropertyInfo propertyInfo) [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxLeafPropertyInfoSourceBinding..ctor (System.Object 源,System.Reflection.PropertyInfo propertyInfo) [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxSimpleLeafPropertyInfoSourceBinding..ctor (System.Object 源,System.Reflection.PropertyInfo propertyInfo) [0x00000] 在 :0 处 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 剩余令牌, 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 剩余令牌, IMvxSourceBinding& 结果)[0x00000] in :0 at Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxSourceBindingFactory.CreateBinding (System.Object 源,IList1 令牌)[0x00000] in :0 at Cirrious.MvvmCross.Binding.Bindings.Source.Construction.MvxSourceBindingFactory.CreateBinding (System.Object 源,System.String 组合属性名称)[0x00000] 在 :0 在 Cirrious.MvvmCross.Binding.Bindings.SourceSteps.MvxPathSourceStep.OnDataContextChanged () [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Bindings.SourceSteps.MvxSourceStep.set_DataContext (System.Object 值)[0x00000] in :0 at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.CreateSourceBinding (System.Object 源)[0x00000] in :0 at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding..ctor (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder.BindSingle (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder+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] 在 :0 处 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].Apply () [0x00000] 在 :0 处 Cirrious.MvvmCross.Binding.BindingContext.MvxFluentBindingDescriptionSet2[CrossLightTouch.MyViewController,CrossLightTouch.ViewModels.MyViewModel].Apply () [0x00000] in:0 在 CrossLightTouch.MyViewController.ViewDidLoad () [0x0024f] 在 /Users/admin/Downloads/N-39-CrossLight-Touch/CrossLightTouch/MyViewController.cs:81 at at(包装器托管到本机) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr) 在 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] 在 /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] 在 /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 构建选项 -> Link Behavior -> Don't link ,它可以在设备上正常工作,但二进制大小增加了一倍。

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

是否有解决方法或替代方法?

【问题讨论】:

  • 尝试从 github.com/MvvmCross/MvvmCross/blob/v3/nuspec/TouchContent/… 添加这个 LinkerPleaseInclude.cs。它没有用。但是,当使用 mtouch 参数 --linkskip=System 并将行为链接到 Link SDK 程序集时,它只能在设备上运行。链接器没有剥离我的任何符号,缺少 sourceEventInfo,这是 MvvmCross 代码的内部。所以修复应该是 MvvmCross 代码的一部分,如果他们的代码的任何符号被优化,开发人员可以包含 LinkerPleaseInclude.cs,我认为不是这种情况。
  • 应该在 LinkerPleaseInclude.cs 文件中添加什么来解决此问题,而不是 --linkskip=System ?

标签: xamarin.ios mvvmcross


【解决方案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 文件中添加引用会强制包含它们。

【讨论】:

  • 我对此表示赞同,因为在我的情况下,我使用了 textView 的解决方法(在视图中确实加载了 - 设置文本 - 这违背了整个使用绑定)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 1970-01-01
  • 1970-01-01
  • 2017-05-19
  • 2010-10-11
相关资源
最近更新 更多