Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

System.Reflection.TargetInvocationException:Exception has been thrown by the target of an invocation

12oni12oni Member ✭✭

Hello community,

I set up a Xamarin.Forms Project with Xamarin.Android.
Iam using Google Firestore with the Plugin.CloudFirestore plugin.

On my ProfilePage I have a CollectionView with Items. When I select one Item I want to go to the ItemDetailPage where I can edit the Item.

I'm using MVVM.

The following Exception occurs when I am selecting an Item to go to the ItemDetailPage. On the ItemDetailViewModel I have a simple property. When I'm leaving one assignment the crash does not occur:

private double price;
    public double Price
    {
        get
        {
            return price;
        }
        set
        {
            price = value;
            Item.Price = price; //when I comment out this line everything works fine
            OnPropertyChanged("Price");
            OnPropertyChanged("Item");
        }
    }

Item is also a Property within the ItemDetailViewModel:

private Item item;
    public Item Item
    {
        get
        {
            return item;
        }
        set
        {
            item = value;
            Title = item.Title;
            Description = item.Description;
            Url = item.Url;
            Price = item.Price;
            OnPropertyChanged("Item");
        }
    }

Output:

Resolved pending breakpoint at 'C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ItemDetailViewModel.cs:95,1' to void Project.ViewModels.ItemDetailViewModel.set_Price (double value) [0x00008].
**System.Reflection.TargetInvocationException:** 'Exception has been thrown by the target of an invocation.'

Thread finished: <Thread Pool> #7
The thread 0x7 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #6
The thread 0x6 has exited with code 0 (0x0).
Thread started: <Thread Pool> #10
12-08 19:03:27.183 D/Mono    ( 6809): DllImport searching in: '__Internal' ('(null)').
12-08 19:03:27.183 D/Mono    ( 6809): Searching for 'java_interop_jnienv_throw'.
12-08 19:03:27.183 D/Mono    ( 6809): Probing 'java_interop_jnienv_throw'.
12-08 19:03:27.183 D/Mono    ( 6809): Found as 'java_interop_jnienv_throw'.
Thread started: <Thread Pool> #11
Thread started: <Thread Pool> #12
**System.Reflection.TargetInvocationException:** 'Exception has been thrown by the target of an invocation.'

12-08 19:03:30.480 E/mono    ( 6809): 
12-08 19:03:30.480 E/mono    ( 6809): Unhandled Exception:
12-08 19:03:30.480 E/mono    ( 6809): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
12-08 19:03:30.480 E/mono    ( 6809):   at Project.ViewModels.ItemDetailViewModel.set_Price (System.Double value) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ItemDetailViewModel.cs:95 
12-08 19:03:30.480 E/mono    ( 6809):   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
12-08 19:03:30.480 E/mono    ( 6809):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
12-08 19:03:30.480 E/mono    ( 6809):    --- End of inner exception stack trace ---
12-08 19:03:30.480 E/mono    ( 6809):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
12-08 19:03:30.480 E/mono    ( 6809):   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
12-08 19:03:30.480 E/mono    ( 6809):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x002f7] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:183 
12-08 19:03:30.480 E/mono    ( 6809):   at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:53 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Binding.Apply (System.Boolean fromTarget) [0x00020] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:119 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00105] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:457 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00214] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:155 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:72 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Binding.Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged) [0x0006d] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:138 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext, System.Boolean fromBindingContextChanged) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:480 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:209 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:475 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element value) [0x000d2] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:197 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:320 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:774 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Layout`1[T].OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:22 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View view) [0x0001d] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:432 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:422 
12-08 19:03:30.481 E/mono    ( 6809):   at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
12-08 19:03:30.481 E/mono    ( 6809):   at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
12-08 19:03:30.481 E/mono    ( 6809):   at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338 
12-08 19:03:30.481 E/mono    ( 6809):   at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196 
12-08 19:03:30.481 E/mono    ( 6809):   at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:71 
12-08 19:03:30.481 E/mono    ( 6809):   at Xamarin.Forms.ObservableWrapper`2[TTrack,TRestrict].Add (TRestrict item) [0x0004b] in D:\a\1\s\Xamarin.Forms.Core\ObservableWrapper.cs:35 
12-08 19:03:30.481 E/mono    ( 6809):   at Project.Views.ItemDetailPage.InitializeComponent () [0x00012] in C:\Users\InroCusher\source\repos\Project\Project\Project\obj\Debug
etstandard2.0\Views\ItemDetailPage.xaml.g.cs:22 
12-08 19:03:30.481 E/mono    ( 6809):   at Project.Views.ItemDetailPage..ctor (Project.Models.Item selectedItem) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\Views\ItemDetailPage.xaml.cs:25 
12-08 19:03:30.481 E/mono    ( 6809):   at Project.ViewModels.ProfilViewModel.set_SelectedItem (Project.Models.Item value) [0x00021] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ProfilViewModel.cs:42 
12-08 19:03:30.481 E/mono    ( 6809):   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
12-08 19:03:30.481 E/mono    ( 6809):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
12-08 19:03:30.481 E/mono    ( 6809):    --- End of inner exception stack trace ---
12-08 19:03:30.481 E/mono    ( 6809):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.100(intptr,intptr,intptr,intptr,int,long)
12-08 19:03:30.481 E/mono    ( 6809):   at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.100(intptr,intptr,intptr,intptr,int,long)
12-08 19:03:30.483 E/mono-rt ( 6809): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
12-08 19:03:30.483 E/mono-rt ( 6809):   at Project.ViewModels.ItemDetailViewModel.set_Price (System.Double value) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ItemDetailViewModel.cs:95 
12-08 19:03:30.483 E/mono-rt ( 6809):   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
12-08 19:03:30.483 E/mono-rt ( 6809):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
12-08 19:03:30.483 E/mono-rt ( 6809):    --- End of inner exception stack trace ---
12-08 19:03:30.483 E/mono-rt ( 6809):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
12-08 19:03:30.483 E/mono-rt ( 6809):   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x002f7] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:183 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:53 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.Binding.Apply (System.Boolean fromTarget) [0x00020] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:119 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00105] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:457 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00214] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:155 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:72 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.Binding.Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged) [0x0006d] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:138 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext, System.Boolean fromBindingContextChanged) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:480 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:209 
12-08 19:03:30.483 E/mono-rt ( 6809):   at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\a\1\s\Xamarin.Forms.C
12-08 19:03:30.483 D/HostConnection( 6809): HostConnection::get() New Host Connection established 0xebb21900, tid 6809
12-08 19:03:30.486 D/HostConnection( 6809): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2

Can anybody help? If more code is needed I can provide it. Thank you!

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    This exception typically comes, when the page you want to navigate to cannot be instantiated. Either due to an error in the ItemDetailPag.xaml or an exception in the constructor.

    Add a try/catch around your navigation code and look at the InnerException of the TargetInvocationException to get more info.

    If you update the Price value, why you add OnPropertyChanged("Price"); in the set method? Normally, we set the Price in the Model like following format.

      private double price;
            public double Price
            {
                get
                {
                    return price;
                }
                set
                {
                    if (price != value)
                    {
                        price = value;
                        OnPropertyChanged("Price");
                    }
                }
            }
    

    In the ItemDetailViewModel, normally, we update the Item like following way.

      private Item item;
            public Item Item
            {
                get
                {
                    return item;
                }
                set
                {
                    if (item != value)
                    {
                        item = value;
                        OnPropertyChanged("Item");
    
                    }
    
                }
            }
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • 12oni12oni Member ✭✭

    I'm new in Programming Xamarin Apps. I make a tutorial where I learned it that way. When I make it your way the exception doesn't appear. :)

    This is the output when I wrap a Try and Catch around the navigation before I make your changes:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
      at Project.ViewModels.ItemDetailViewModel.set_Price (System.Double value) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ItemDetailViewModel.cs:93 
      at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
      at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
       --- End of inner exception stack trace ---
      at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection12-09 10:35:38.343 I/mono-stdout(11366): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    
    12-09 10:35:38.344 I/mono-stdout(11366):   at Project.ViewModels.ItemDetailViewModel.set_Price (System.Double value) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ItemDetailViewModel.cs:93 .BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
      at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
      at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x002f7] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:183 
      at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:53 
      at Xamarin.Forms.Binding.Apply (System.Boolean fromTarget) [0x00020] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:119 
    
    
    12-09 10:35:38.344 I/mono-stdout(11366):   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00105] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:457 
      at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397 
      at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00214] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:155 
      at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty
    
     property) [0x0006b] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:72 
      at Xamarin.Forms.Binding.Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged) [0x0006d] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:138 
      at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext, System.Boolean fromBindingContextChanged) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:480 
      at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:209 
      at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:475 
      at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element value) [0x000d2] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:197 
      at Xamarin.Forms.Element.OnChildAd12-09 10:35:38.344 I/mono-stdout(11366):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 
    
    ded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:320 
      at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:774 
      at Xamarin.Forms.Layout`1[T].OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:22 
      at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View view) [0x0001d] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:432 
      at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:422 
      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) [0x00018] in /Users12-09 10:35:38.344 I/mono-stdout(11366):    --- End of inner exception stack trace ---
    
    /builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
      at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338 
      at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196 
      at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/Syst12-09 10:35:38.344 I/mono-stdout(11366):   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:409 
    
    em/Collections/ObjectModel/Collection.cs:71 
      at Xamarin.Forms.ObservableWrapper`2[TTrack,TRestrict].Add (TRestrict item) [0x0004b] in D:\a\1\s\Xamarin.Forms.Core\ObservableWrapper.cs:35 
      at Project.Views.ItemDetailPage.InitializeComponent () [0x00012] in C:\Users\InroCusher\source\repos\Project\Project\Project\obj\Debug
    etstandard2.0\Views\ItemDetailPage.xaml.g.cs:22 
      at Project.Views.ItemDetailPage..ctor (Project.Models.Item selectedItem) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\Views\ItemDetailPage.xaml.cs:25 
      at Project.ViewModels.ProfilViewModel.set_SelectedItem (Project.Models.Item value) [0x00023] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ProfilViewModel.cs:32 12-09 10:35:38.344 I/mono-stdout(11366):   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 
    
    12-09 10:35:38.344 I/mono-stdout(11366):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x002f7] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:183 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:53 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.Binding.Apply (System.Boolean fromTarget) [0x00020] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:119 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00105] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:457 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00214] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:155 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:72 
    12-09 10:35:38.345 I/mono-stdout(11366):   at Xamarin.Forms.Binding.Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged) [0x0006d] in D:\a\1\s\Xamarin.Forms.Core\Binding.cs:138 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext, System.Boolean fromBindingContextChanged) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:480 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:209 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:475 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element value) [0x000d2] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:197 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:320 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:774 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Layout`1[T].OnChildAdded (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:22 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View view) [0x0001d] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:432 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:422 
    12-09 10:35:38.346 I/mono-stdout(11366):   at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
    12-09 10:35:38.346 I/mono-stdout(11366):   at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
    12-09 10:35:38.346 I/mono-stdout(11366):   at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338 
    12-09 10:35:38.346 I/mono-stdout(11366):   at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196 
    12-09 10:35:38.346 I/mono-stdout(11366):   at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:71 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Xamarin.Forms.ObservableWrapper`2[TTrack,TRestrict].Add (TRestrict item) [0x0004b] in D:\a\1\s\Xamarin.Forms.Core\ObservableWrapper.cs:35 
    12-09 10:35:38.346 I/mono-stdout(11366):   at Project.Views.ItemDetailPage.InitializeComponent () [0x00012] in C:\Users\InroCusher\source\repos\Project\Project\Project\obj\Debug
    etstandard2.0\Views\ItemDetailPage.xaml.g.cs:22 
    12-09 10:35:38.347 I/mono-stdout(11366):   at Project.Views.ItemDetailPage..ctor (Project.Models.Item selectedItem) [0x00008] in C:\Users\InroCusher\source\repos\Project\Project\Project\Views\ItemDetailPage.xaml.cs:25 
    12-09 10:35:38.347 I/mono-stdout(11366):   at Project.ViewModels.ProfilViewModel.set_SelectedItem (Project.Models.Item value) [0x00023] in C:\Users\InroCusher\source\repos\Project\Project\Project\ViewModels\ProfilViewModel.cs:32 
    
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Could you share your navigate part of code from ProfilePage to ItemDetailPage?

  • 12oni12oni Member ✭✭

    Of course:

    This is in my ProfilPageViewModel :

        public Wish SelectedWish
        {
            get
            {
                return selectedWish;
            }
            set
            {
                selectedWish = value;
                OnPropertyChanged("SelectedWish");
                if(selectedWish != null)
                {
                    try
                    {
                        App.Current.MainPage.Navigation.PushAsync(new WishDetailPage(selectedWish));
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex);
                    }
                }                   
            }
        }
    

    This is the constructor in my ItemDetailPage :

        public WishDetailPage(Wish selectedWish)
        {
            InitializeComponent();
            wishDetailViewModel = Resources["WishDetailViewModel"] as WishDetailViewModel;
            wishDetailViewModel.Wish = selectedWish;
        }
    

    But actually I am pretty happy with yout solution provided before. If you dont see any issue in this code i would just close the thread. :)

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    I test your code, I found when execute this line wishDetailViewModel = Resources["WishDetailViewModel"] as WishDetailViewModel; could you give me prompt about this code.

     public ItemsDetailsPage(Item selectedWish)
            {
                InitializeComponent();
                //ItemDetailViewModel itemDetailViewModel = Resources["ItemDetailViewModel"] as ItemDetailViewModel;
            //      itemDetailViewModel.Item = selectedWish;
                name.Text = selectedWish.Name;
                price.Text = selectedWish.Price.ToString();
                MyButton.Clicked += async (sender, args) =>
                {
                    selectedWish.Name = name.Text;
                    selectedWish.Price = Double.Parse(price.Text);
                    await  Navigation.PushModalAsync(new MainPage());
                };
            }
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.