IMvxTouchModalHost not resolvable when using custom presenter - ios

I've created a custom service which needs a reference to my custom presenter, but I get an error on resolving IMvxTouchModalHost. By using the default MvxTouchViewPresenter, everything works fine.
Here is my code:
AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
this.window = new UIWindow(UIScreen.MainScreen.Bounds);
var presenter = new AppViewPresenter(this, this.window);
var setup = new Setup(this, presenter);
setup.Initialize();
Mvx.Resolve<IMvxAppStart>().Start();
this.window.MakeKeyAndVisible();
}
AppViewPresenter.cs
public class AppViewPresenter : MvxTouchViewPresenter
{
private IMvxTouchViewCreator viewCreator;
protected IMvxTouchViewCreator ViewCreator
{
get { return this.viewCreator ?? (this.viewCreator = Mvx.Resolve<IMvxTouchViewCreator>()); }
}
public AppViewPresenter(IUIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
}
protected override void OnMasterNavigationControllerCreated()
{
this.MasterNavigationController.WeakDelegate = new NavigationControllerDelegate();
}
public override void Show(MvxViewModelRequest request)
{
var nextViewController = (UIViewController)this.ViewCreator.CreateView(request);
if (nextViewController is IMvxModalTouchView)
{
nextViewController.TransitioningDelegate = new NavigationControllerTransitioningDelegate();
nextViewController.ModalPresentationStyle = UIModalPresentationStyle.Custom;
this.CurrentTopViewController.PresentViewController(nextViewController, true, null);
}
else
{
base.Show(request);
}
if (request.PresentationValues != null)
{
if (request.PresentationValues.ContainsKey("ClearStack") && this.CurrentTopViewController != null)
{
if (this.CurrentTopViewController.GetType() != nextViewController.GetType())
{
this.MasterNavigationController.PopToRootViewController(true);
}
}
}
}
public override void Close(IMvxViewModel toClose)
{
if (this.CurrentTopViewController.PresentedViewController != null)
{
this.CurrentTopViewController.DismissModalViewController(true);
}
else
{
base.Close(toClose);
}
}
}
Setup.cs
public class Setup : MvxTouchSetup
{
public Setup(MvxApplicationDelegate appDelegate, IMvxTouchViewPresenter presenter)
: base(appDelegate, presenter)
{
}
protected override IMvxApplication CreateApp()
{
return new App.Core.Infrastructure.App();
}
protected override IMvxTouchViewsContainer CreateTouchViewsContainer()
{
return new AppViewContainer();
}
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
base.FillTargetFactories(registry);
registry.RegisterPropertyInfoBindingFactory(typeof(MvxUIPageControlCurrentPageTargetBinding), typeof(UIPageControl),
"CurrentPage");
}
}
CustomService.cs
public class CustomService : BaseService, ICustomService
{
private readonly IMvxTouchModalHost modalHost;
public CustomService()
{
this.modalHost = Mvx.Resolve<IMvxTouchModalHost>();
}
}
Exception is thrown in ctor of CustomService:
Cirrious.CrossCore.Exceptions.MvxIoCResolveException: Failed to resolve parameter for parameter window of type UIWindow when creating App.Infrastructure.AppViewPresenter
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x0006e] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00031] in <filename unknown>:0
at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00006] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxLazySingletonCreator.get_Instance () [0x00020] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxTypeExtensions+<>c__DisplayClass49.<RegisterAsLazySingleton>b__48 () [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve () [0x00028] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, IResolver resolver, System.Object& resolved) [0x00042] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, Nullable1 requiredResolverType, System.Object& resolved) [0x0002e] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00011] in <filename unknown>:0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve[T] () [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.Mvx.Resolve[TService] () [0x00006] in <filename unknown>:0
at App.Services.CustomService..ctor () [0x00009] in c:\Src\App\iPhone\Services\CustomService.cs:24

Got it. I accidently removed .EndingWith("Service") in service registration.
So, in App.cs there must be, of course, any filter for registration. Otherwise it reregisters everything. So, changed registration from
this.CreatableTypes().AsInterfaces().RegisterAsLazySingleton();
to e.g.
this.CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsLazySingleton();
solved it.

Related

mvvmcross Android. Cannot access a disposed object on Enabled Binding

After repeating visiting screen, I get next error:
System.ObjectDisposedException: Cannot access a disposed object. at
Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable
self) [0x00029] in <286213b9e14c442ba8d8d94cc9dbec8e>:0 07-03
11:29:51.230 I/MonoDroid(20631): at
Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod
(System.String encodedMember, Java.Interop.IJavaPeerable self,
Java.Interop.JniArgumentValue* parameters) [0x00000] in
<286213b9e14c442ba8d8d94cc9dbec8e>:0 07-03 11:29:51.230
I/MonoDroid(20631): at Android.Views.View.set_Enabled
(System.Boolean value) [0x00022] in
:0 07-03 11:29:51.230
I/MonoDroid(20631): at
MvvmCross.Platforms.Android.Binding.Target.MvxViewClickBinding.RefreshEnabledState
() [0x00022] in
C:\projects\mvvmcross\MvvmCross\Platforms\Android\Binding\Target\MvxViewClickBinding.cs:64
07-03 11:29:51.230 I/MonoDroid(20631): at
MvvmCross.Platforms.Android.Binding.Target.MvxViewClickBinding.OnCanExecuteChanged
(System.Object sender, System.EventArgs e) [0x00000] in
C:\projects\mvvmcross\MvvmCross\Platforms\Android\Binding\Target\MvxViewClickBinding.cs:69
07-03 11:29:51.230 I/MonoDroid(20631): at (wrapper
managed-to-native)
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
07-03 11:29:51.230 I/MonoDroid(20631): at
System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object[] parameters, System.Globalization.CultureInfo
culture) [0x0003b] in :0 07-03
11:29:51.230 I/MonoDroid(20631): --- End of inner exception stack
trace --- 07-03 11:29:51.230 I/MonoDroid(20631): at
System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object[] parameters, System.Globalization.CultureInfo
culture) [0x00054] in :0 07-03
11:29:51.230 I/MonoDroid(20631): at
System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] in
:0 07-03 11:29:51.230
I/MonoDroid(20631): at
MvvmCross.WeakSubscription.MvxWeakEventSubscription`2[TSource,TEventArgs].OnSourceEvent
(System.Object sender, TEventArgs e) [0x0000a] in
C:\projects\mvvmcross\MvvmCross\WeakSubscription\MvxWeakEventSubscription.cs:74
07-03 11:29:51.230 I/MonoDroid(20631): at
MvvmCross.Commands.MvxWeakCommandHelper.RaiseCanExecuteChanged
(System.Object sender) [0x00014] in
C:\projects\mvvmcross\MvvmCross\Commands\MvxCommand.cs:96 07-03
11:29:51.230 I/MonoDroid(20631): at
MvvmCross.Commands.MvxCommandBase.b__9_0 ()
[0x00000] in
C:\projects\mvvmcross\MvvmCross\Commands\MvxCommand.cs:135
Not sure, if this android or mvvmcross issue. Can I avoid invoking view in MvxViewClickBinding, if it disposed?
I guess you could write a static extension method for Java.Lang.Object like below:
public static class ObjectExtensions
{
public static bool IsDisposedOrNull(this Object objectValue)
{
return objectValue?.Handle == IntPtr.Zero;
}
}

Can't send big json (with byte array inside) to server using xamarin ios single view application

I can't send a lot of data (json with byte array inside) from xamarin ios single view app to server ASP .NET.
My models (same on ios app and server)
public class VirtualTourDataModel
{
public string VTName { get; set; }
public List<ViewPoint> ViewPoints { get; set; }
}
public class ViewPoint
{
public string PointName { get; set; }
public byte[] Video { get; set; }
public List<bool> Connections { get; set; }
}
how i set bytearray:
ViewPoint viewPoint = new ViewPoint();
viewPoint.Video = ToByteArray(NSData.FromUrl(outputFileUrl));
VirtualTourData.ViewPoints.Add(viewPoint);
public static byte[] ToByteArray(NSData data)
{
var bytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, bytes, 0, Convert.ToInt32(data.Length));
return bytes;
}
How do i send data:
VirtualTourDataModel vtModel = new VirtualTourDataModel();
vtModel.VTName = VirtualTourData.VTName;
vtModel.ViewPoints = VirtualTourData.ViewPoints;
var json = JsonConvert.SerializeObject(vtModel);
string sUrl = "http://192.168.0.56:6240/api/UploadVT/Upload";
try
{
using (var httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromMinutes(1);
httpClient.BaseAddress = new Uri("http://192.168.0.56:6240");
var content = new StringContent(json, Encoding.UTF8, "application/json");
var url = new Uri(string.Concat("http://192.168.0.56:6240", "/api/UploadVT/Upload"));
HttpResponseMessage response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
// this result string should be something like: "{"token":"rgh2ghgdsfds"}"
var result = await response.Content.ReadAsStringAsync();
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
I receive this error in catch:
{System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
at System.Net.WebConnectionStream.EndWrite (System.IAsyncResult r) [0x000b9] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/System/System.Net/WebConnectionStream.cs:617
at System.IO.Stream+<>c.b__53_1 (System.IO.Stream stream, System.IAsyncResult asyncResult) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/io/stream.cs:729
at System.Threading.Tasks.TaskFactory1+FromAsyncTrimPromise1[TResult,TInstance].Complete (TInstance thisRef, System.Func3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:1441
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:447
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x00324] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:379
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0
at System.Net.Http.HttpClient+d__48.MoveNext () [0x00080] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in :0
at EasyVTApp.VTLinkViewController+d__2.MoveNext () [0x00107] in D:\magistr\EasyVTApp\EasyVTApp\VTLinkViewController.cs:79 }

Xamarion iOS DatePickerRenderer

I've writed for my Xamarin application a couple of CustomDatePickerRenderer for Android and iOS. For Android all works fine, for iOS no. I've when create the DatePicker Control an exception for an invalid cast.
Here the code(simplyfied):
Xamarin interface
class CustomDatePicker : Xamarin.Forms.DatePicker
{
}
iOS Renderer
class CustomDatePickerRenderer : DatePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control == null)
{
return;
}
}
}
Exception
System.InvalidCastException: Specified cast is not valid.
at (wrapper castclass) System.Object:__castclass_with_cache (object,intptr,intptr)
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <4cf9e9e173a04ea3aa841c775e6a23d7>:0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Platform.cs:192
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00009] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:63
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:36
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000cc] in <4cf9e9e173a04ea3aa841c775e6a23d7>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <4cf9e9e173a04ea3aa841c775e6a23d7>:0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Platform.cs:192
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00009] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:63
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:36
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000cc] in <4cf9e9e173a04ea3aa841c775e6a23d7>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <4cf9e9e173a04ea3aa841c775e6a23d7>:0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Platform.cs:192
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00009] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:63
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x0000f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:113
at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x00029] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:354
at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:570
at Xamarin.Forms.Layout`1[T].OnChildAdded (Xamarin.Forms.Element child) [0x00000] in <051840eae40a4636884ee6bc6a0d140a>:0
at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View view) [0x0001d] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:406
at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00089] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:396
at (wrapper delegate-invoke) <Module>:invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in <c3954baf21fc42d6b4b50ba067398247>:0
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00009] in <c3954baf21fc42d6b4b50ba067398247>:0
at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x00024] in <c3954baf21fc42d6b4b50ba067398247>:0
at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00023] in <15e850188d9f425bbeae90f0bbc51e17>:0
at Xamarin.Forms.ObservableWrapper`2[TTrack,TRestrict].Add (TRestrict item) [0x0004b] in <051840eae40a4636884ee6bc6a0d140a>:0
at Xamarin.Forms.RelativeLayout+RelativeElementCollection.Add (Xamarin.Forms.View view, Xamarin.Forms.Constraint xConstraint, Xamarin.Forms.Constraint yConstraint, Xamarin.Forms.Constraint widthConstraint, Xamarin.Forms.Constraint heightConstraint) [0x00012] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\RelativeLayout.cs:313
at ArgonApp.InserimentoAutoletturaPage+<selectPage>c__async3.MoveNext () [0x00241] in /Users/alessandro/Desktop/Argon Whitelabel/ArgonApp/ArgonApp/Views/InserimentoAutoletturaPage.xaml.cs:406
Have you any idea on this problem?
Thanks.

Mvvmcross binding failure with "Use Shared Runtime" unchecked on Xamarin.Android

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
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

MvvmCross: Using custom MvxAdapter from fragments

I am trying to add a header and footer to an MvxListView by using my own custom MvxAdapter.
From an Activity, I can just add the adapter to the listview in the OnCreate() method, and it just works.
But if I try to do the same from the OnCreateView() in a Fragment I get a Java.Lang.RuntimeException with the following stack trace:
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod) [0x00000] in <filename unknown>:0
at Android.Widget.BaseAdapter.NotifyDataSetChanged () [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Droid.Views.MvxAdapter.NotifyDataSetChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Droid.Views.MvxAdapter.OnItemsSourceCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0
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
--- End of managed exception stack trace ---
java.lang.NullPointerException
at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Am I missing something here?
Thanks!

Resources