【问题标题】:Binding in MvvmCross test application for Android does not work (TargetInvocationException)Android 的 MvvmCross 测试应用程序中的绑定不起作用 (TargetInvocationException)
【发布时间】:2013-10-17 20:50:15
【问题描述】:

我正在尝试了解适用于 Android 的 Xamarin Studio MvvmCross 示例。 我在这里上传了我的解决方案版本:https://github.com/Krumelur/MvvmCrossTest

我的环境是 XS 4.0.13、X.iOS 7.0.2.7、X.Android 4.8.3。所有独立版。

我尝试了 Stuart 博客文章中的版本,但我无法构建它,因为它需要 Xamarin 商业许可证,因为它引用了 System.ServiceModel,所以我无法比较它是否可以在那里工作。

运行应用程序时,每次在文本字段中输入字符时都会出现以下异常:

[0:] MvxBind:Error:132.38 SetValue failed with exception - TargetInvocationException: Exception has been thrown by the target of an invocation.
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <filename unknown>:0 
  at Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxLeafPropertyInfoSourceBinding.SetValue (System.Object value) [0x00080] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Binding\Bindings\Source\Leaf\MvxLeafPropertyInfoSourceBinding.cs:86 
InnerException was TypeLoadException: Could not load type 'System.Linq.Expressions.Expression' from assembly 'AndroidDemo.Core'.
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

  at Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxLeafPropertyInfoSourceBinding.SetValue (System.Object value) [0x00080] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Binding\Bindings\Source\Leaf\MvxLeafPropertyInfoSourceBinding.cs:86 
InnerException was TypeLoadException: Could not load type 'System.Linq.Expressions.Expression' from assembly 'AndroidDemo.Core'.
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

【问题讨论】:

    标签: android xamarin.android xamarin mvvmcross


    【解决方案1】:

    在将核心项目作为 PCL 时,System.Linq.Expressions.Expression 中存在一个错误,并且已报告 on Xamarin's Bugzilla

    您可以按照那里的说明制作自己的外观组件,或者在您的ViewModel 中将RaisePropertyChanged 更改为:

    RaisePropertyChanged(() => this.Foo);
    

    到:

    RaisePropertyChanged("Foo");
    

    【讨论】:

    • 您可以对您的属性进行所有这些更改,只是为了让 Linq 异常在其他地方弹出 - 例如内部 mvvmcross ViewModel 匹配。我会等到他们修复它,或者正如你所说,每次安装新版本的 mono.droid 后,将外观组件替换为固定的组件。
    【解决方案2】:

    您的测试项目第一次在这里工作

    我的详细信息:

    Xamarin Studio
    Version 4.0.12 (build 3)
    Installation UUID: 683340a3-6ed3-4d10-ba59-9fc326c5ff7c
    Runtime:
        Mono 3.2.3 ((no/8d3b4b7)
        GTK 2.24.20
        GTK# (2.12.0.0)
        Package version: 302030000
    
    Apple Developer Tools
    Xcode 5.0 (3332.25)
    Build 5A1413
    
    Xamarin.Mac
    Xamarin.Mac: Not Installed
    
    Xamarin.Android
    Version: 4.8.1 (Business Edition)
    Android SDK: /Users/stuartlodge/Library/Developer/Xamarin/android-sdk-mac_x86
        Supported Android versions:
            1.6   (API level 4)
            2.1   (API level 7)
            2.2   (API level 8)
            2.3   (API level 10)
            3.1   (API level 12)
            4.0   (API level 14)
            4.0.3 (API level 15)
            4.2   (API level 17)
    Java SDK: /usr
    java version "1.6.0_51"
    Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
    Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
    
    Xamarin.iOS
    Version: 7.0.1.4 (Business Edition)
    Hash: 4cfca2f
    Branch: 
    Build date: 2013-20-09 23:14:32-0400
    
    Build Information
    Release ID: 400120003
    Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
    Build date: 2013-08-07 20:30:53+0000
    Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873
    
    Operating System
    Mac OS X 10.8.5
    Darwin Stuarts-MacBook-Air.local 12.5.0 Darwin Kernel Version 12.5.0
        Mon Jul 29 16:33:49 PDT 2013
        root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64
    

    鉴于 Xamarin 之前遇到过 System.Linq.Expressions.Expression 的问题,这可能是 Xamarin.Android 4.8.1 和 4.8.3 之间的问题?

    ...所以我更新了...

    是的,我看到了与您在 4.8.3 上看到的相同的问题

    因此,Xamarin 似乎已将更多 PCL 更新发布到稳定版,而无需针对已知问题进行测试 :(

    要解决此问题:

    • 您可以回滚到 4.8.1
    • 您可以使用RaisePropertyChanged("Foo") 代替RaisePropertyChanged(() =&gt; Foo)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多