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.
Related
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;
}
}
This post seems to be here a few more than a few times but I have gone through all of those and adjusted the code to have the true DLL name but still get the Unable to load the specified metadata resource error.
Now what comes the interesting part, this code works on the machine it was developed on in VS but does not work on any other machines or live version. I am not sure if this has anything to do with it.
Here is the Connection String - (Sources/Pass have been replaced with *)
<add name="RMUplistEntities" connectionString="metadata=res://RM.Data/DataEntities.Model1.csdl|res://RM.Data/DataEntities.Model1.ssdl|res://RM.Data/DataEntities.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=*;initial catalog=RMUplist;user id=*;password=*;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This is the stack trace
Exception stack trace:
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.LoadResource () [0x00016] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.CreateReader () [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.CreateReaders (System.Data.Entity.Core.Metadata.Edm.DataSpace spaceToGet) [0x0001c] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderComposite.CreateReaders (System.Data.Entity.Core.Metadata.Edm.DataSpace spaceToGet) [0x0001b] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadEdmItemCollection (System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader loader) [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataCache+<>c__DisplayClass5.<GetMetadataWorkspace>b__0 (System.String k) [0x0000d] in <000f54522ad145bf987b3043022f9799>:0
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00034] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/external/corefx/src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs:1035
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace (System.String cacheKey, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader artifactLoader) [0x0000d] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace (System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions effectiveConnectionOptions) [0x0001f] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace () [0x0000f] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection () [0x00014] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Objects.ObjectContext..ctor (System.Data.Entity.Core.EntityClient.EntityConnection connection, System.Boolean isConnectionConstructor, System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, System.Data.Entity.Core.Common.Internal.Materialization.Translator translator, System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory columnMapFactory) [0x000ea] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Core.Objects.ObjectContext..ctor (System.Data.Entity.Core.EntityClient.EntityConnection connection) [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel () [0x00006] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel () [0x00006] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x0007c] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <000f54522ad145bf987b3043022f9799>:0
at System.Data.Entity.Infrastructure.DbQuery`1[TResult].System.Linq.IQueryable.get_Provider () [0x00016] in <000f54522ad145bf987b3043022f9799>:0
at System.Linq.Queryable.Where[TSource] (System.Linq.IQueryable`1[T] source, System.Linq.Expressions.Expression`1[TDelegate] predicate) [0x0001c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/external/corefx/src/System.Linq.Queryable/src/System/Linq/Queryable.cs:39
at RM.UpList.Controllers.HomeController.DailyRotation (System.Nullable`1[T] date) [0x00099] in /*/RMUplist-master/RM.UpList/Controllers/HomeController.cs:109
at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase controller, System.Object[] parameters) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext controllerContext, System.Collections.Generic.IDictionary`2[TKey,TValue] parameters) [0x00072] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionDescriptor actionDescriptor, System.Collections.Generic.IDictionary`2[TKey,TValue] parameters) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation.InvokeSynchronousActionMethod () [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39 (System.IAsyncResult asyncResult, System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation innerInvokeState) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeDelegate`2[System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation,System.Web.Mvc.ActionResult]:invoke_TResult_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.Async.AsyncControllerActionInvoker/ActionInvocation)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`2[TResult,TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d () [0x00014] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f () [0x00086] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32 (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[TResult].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21+<>c__DisplayClass2b.<BeginInvokeAction>b__1c () [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__1e (System.IAsyncResult asyncResult) [0x00041] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[TResult].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d (System.IAsyncResult asyncResult, System.Web.Mvc.Controller+ExecuteCoreState innerState) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeVoidDelegate`1[System.Web.Mvc.Controller+ExecuteCoreState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.Controller/ExecuteCoreState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Controller.EndExecuteCore (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Controller.<BeginExecute>b__15 (System.IAsyncResult asyncResult, System.Web.Mvc.Controller controller) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Controller.EndExecute (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5 (System.IAsyncResult asyncResult, System.Web.Mvc.MvcHandler+ProcessRequestState innerState) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeVoidDelegate`1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.MvcHandler.EndProcessRequest (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest (System.IAsyncResult result) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0
at System.Web.HttpApplication.async_handler_complete_cb (System.IAsyncResult ar) [0x00015] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web/HttpApplication.cs:988
This error happens if you have the EDMX in one project and you are using it from another project and the later in not able to load the EDMX files.
Have you tried changing your conenctionstring to
connectionString="metadata=res://*/;
There are also a lot of other possible causes for this. You can google around. This post has a lot of possible solutions.
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.
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
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!