Reputation: 1384
I have an app that works fine in Debug build and mostly works in Release, but I get the stack trace at the bottom of this question. The binding that seems to be failing is the enabled property of the button. I think this because if I take it out the other bindings work. Simplified viewmodel code and ui axml below as well. I've localised the relevant difference between the release and debug builds to the "Use Shared Runtime" build setting. With this selected it works. Without it fails. Unfortunately I can not package the build for distribution if this option is selected. Does anyone have any idea what is going on here?
VisualStudio 2012 Xamarin 3.5.58.0
ui axml snippet for the button that is causing issues
<Button
android:padding="2dip"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Click SendConfigCommand; Enabled ButtonEnabledSendConfig; Text ButtonLabelSendConfig, Mode=OneTime; LongClick HelpCommand, CommandParameter=HelpContinueDevice" />
ViewModel snippet for the properties used by the button (simplified for debuggingbuoi)
public string ButtonLabelSendConfig
{
get{return "Next";}
}
public bool ButtonEnabledSendConfig
{
get { return false; }
}
public ICommand SendConfigCommand
{
get
{
return m_SendConfigCommand ?? (m_SendConfigCommand = new MvxCommand(() =>
{
//Intentionally left empty
}));
}
}
private MvxCommand m_SendConfigCommand;
from viewmodel base class
public MvxCommand<string> HelpCommand
{
get { return this._HelpCommand ?? (this._HelpCommand = new MvxCommand<string>(key =>
{
var prompter = Mvx.Resolve<IUserInteraction>();
prompter.Alert(Localised.ResourceManager.GetString(key), null, Localised.Help, Localised.OkayButton);
})); }
}
private MvxCommand<string> _HelpCommand;
Stack trace
MvxBind:Error:653.39 Exception thrown during the view binding NullReferenceException: Object reference not set to an instance of an object
09-16 13:21:45.456 I/MvxBind (29040): 653.39 Exception thrown during the view binding NullReferenceException: Object reference not set to an instance of an object
at Cirrious.CrossCore.ReflectionExtensions+<>c__DisplayClass7.<GetProperties>b__4 (System.Reflection.PropertyInfo p) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1F`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1E`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1E`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.First[PropertyInfo] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.FirstOrDefault[PropertyInfo] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.ReflectionExtensions.GetProperty (System.Type type, System.String name) [0x00000] in <filename unknown>:0
at Cirrious.M
09-16 13:21:45.456 I/MvxBind (29040): at Cirrious.CrossCore.ReflectionExtensions+<>c__DisplayClass7.<GetProperties>b__4 (System.Reflection.PropertyInfo p) [0x00000] in <filename unknown>:0
[0:] MvxBind:Error:653.39 Exception thrown during the view binding NullReferenceException: Object reference not set to an instance of an object
at Cirrious.CrossCore.ReflectionExtensions+<>c__DisplayClass7.<GetProperties>b__4 (System.Reflection.PropertyInfo p) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1F`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1E`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1E`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.First[PropertyInfo] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.FirstOrDefault[PropertyInfo] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.ReflectionExtensions.GetProperty (System.Type type, System.String name) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.Construction.MvxTargetBindingFactoryRegistry.TryCreateReflectionBasedBinding (System.Object target, System.String targetName, IMvxTargetBinding& binding) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.Construction.MvxTargetBindingFactoryRegistry.CreateBinding (System.Object target, System.String targetName) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.CreateTargetBinding (System.Object target) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding..ctor (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder.BindSingle (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder+<>c__DisplayClass1.<Bind>b__0 (Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription description) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription,Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].MoveNext () [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].AddRange (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Droid.Binders.MvxAndroidViewBinder.ApplyBindingsFromAttribute (Android.Views.View view, Android.Content.Res.TypedArray typedArray, Int32 attributeId) [0x00000] in <filename unknown>:0
vvmCross.Binding.Bindings.Target.Construction.MvxTargetBindingFactoryRegistry.TryCreateReflectionBasedBinding (System.Object target, System.String targetName, IMvxTargetBinding& binding) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.Construction.MvxTargetBindingFactoryRegistry.CreateBinding (System.Object target, System.String targetName) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.CreateTargetBinding (System.Object target) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding..ctor (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder.BindSingle (Cirrious.MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Binders.MvxFromTextBinder+<>c__DisplayClass1.<Bind>b__0 (Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription descr
09-16 13:21:45.456 I/MvxBind (29040): at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1F`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0
iption) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[Cirrious.MvvmCross.Binding.Bindings.MvxBindingDescription,Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].MoveNext () [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Cirrious.MvvmCross.Binding.Bindings.IMvxUpdateableBinding].AddRange (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Droid.Binders.MvxAndroidViewBinder.ApplyBindingsFromAttribute (Android.Views.View view, Android.Content.Res.TypedArray typedArray, Int32 attributeId) [0x00000] in <filename unknown>:0
Upvotes: 0
Views: 467
Reputation: 20312
This is most likely due to the linker. MvvmCross uses reflection to perform databinding. Since the only reference to the Enabled property is in the layout file, the linker doesn't include that in the final assembly.
MvvmCross adds a file in your Android project named LinkerPleaseInclude.cs. You will need to add a reference to the property in there to ensure it gets linked in.
Something like this:
public void Include(Button button)
{
button.Click += (s,e) => button.Text = button.Text + "";
button.Enabled = !button.Enabled;
}
See also: mvvmcross binding on switch fails on release
Upvotes: 2