Given the following method code in a Profile78 Portable Class Library:
public static void Calculate()
{
var constantExpression = System.Linq.Expressions.Expression.Constant(5);
}
When I call the method from a mono.android project (4.7.10024), I get the following exception:
System.TypeLoadException: Could not load type 'System.Linq.Expressions.ConstantExpression' from assembly 'System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I believe this should work as Profile78 does contain the full System.Linq.Expressions dll.
I found this error when I was trying to use MVVM Cross viewmodels in a profile78 PCL. Whenever Mvx needs to update an android databinding, I get the following error (And the above is just me trying to narrow down the problem. Hopefully they have the same root cause):
06-27 09:57:29.229 I/mono-stdout( 3785) MvxBind:Error: 41.72 SetValue failed with exception - TargetInvocationException: Exception has been thrown by the target of an invocation.
06-27 09:57:29.229 I/mono-stdout( 3785) 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
06-27 09:57:29.229 I/mono-stdout( 3785) 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
06-27 09:57:29.229 I/mono-stdout( 3785) at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <filename unknown>:0
06-27 09:57:29.229 I/mono-stdout( 3785) at Cirrious.MvvmCross.Binding.Bindings.Source.Leaf.MvxLeafPropertyInfoSourceBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0
06-27 09:57:29.229 I/mono-stdout( 3785) InnerException was TypeLoadException: Could not load type 'System.Linq.Expressions.Expression' from assembly 'MvxSpike'.
06-27 09:57:29.229 I/mono-stdout( 3785) at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
06-27 09:57:29.229 I/mono-stdout( 3785) 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
06-27 09:57:30.469 W/ ( 3785) Missing method Constant in assembly /data/data/MvxSpike.Android/files/.__override__/MvxSpike.dll, type System.Linq.Expressions.Expression[0]
06-27 09:57:30.469 I/MvxBind ( 3785) 42.97 SetValue failed with exception - TargetInvocationException: Exception has been thrown by the target of an invocation.
06-27 09:57:30.469 I/MvxBind ( 3785) 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
06-27 09:57:30.469 I/MvxBind ( 3785) 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
06-27 09:57:30.469 I/MvxBind ( 3785) at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <filename unknown>:0
MvxBind:Error: 42.97 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) [0x00000] in <filename unknown>:0
InnerException was TypeLoadException: Could not load type 'System.Linq.Expressions.Expression' from assembly 'MvxSpike'.
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
[0:] MvxBind:Error: 42.97 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) [0x00000] in <filename unknown>:0
InnerException was TypeLoadException: Could not load type 'System.Linq.Expressions.Expression' from assembly 'MvxSpike'.
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
It's odd that now the type System.Linq.Expressions.Expression
is now trying to load from my own PCL assembly, but as you can see above it even fails when trying to load from the correct assembly.