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.

UWP Exception

leoadmleoadm Member ✭✭

Hi everyone. Im new on the forum and relatively new in Xamarin.
Im having an issue with an especific exeption that ive tried to understand what does it means. Can someone help me out?
Here is it:
System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.UWP.FormsGridView.OnApplyTemplate()
at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
at Xamarin.Forms.Platform.UWP.VisualElementRenderer2.MeasureOverride(Size availableSize) at Windows.UI.Xaml.UIElement.Measure(Size availableSize) at Xamarin.Forms.Platform.UWP.VisualElementRenderer2.MeasureOverride(Size availableSize)

Sorry for the bad english

Best Answers

  • leoadmleoadm Member ✭✭
    Accepted Answer

    I found where the problem was. It happens when I tried to set the current.mainpage to a new mainpage of the type shell. I was doing that to update the flyout, and im already looking to do that the right way ;) Thanks

  • leoadmleoadm Member ✭✭
    Accepted Answer

    Update: Actually the problem was a refreshview containing a collectionview

Answers

  • leoadmleoadm Member ✭✭

    The real problem is that the StackTrace isnt really helping me out to locate the problem.

  • jezhjezh Member, Xamarin Team Xamurai

    From the log you post, I found you have passed a null instance of an object to method FormsGridView.OnApplyTemplate().
    But I couldn't reproduce this question in my side.

    If it is convenient for you, could you please post a basic demo so that we can help you better?

  • leoadmleoadm Member ✭✭
    edited January 2020

    Thanks for the answer. I'll try to create a demo. But the point is that I dont call this method OnApplyTemplate and I would like to know where xamarin calls it. It is happening in a Shell UWP project and apparently it happens when I call shell.current.popmodalasync()

  • leoadmleoadm Member ✭✭
    Accepted Answer

    I found where the problem was. It happens when I tried to set the current.mainpage to a new mainpage of the type shell. I was doing that to update the flyout, and im already looking to do that the right way ;) Thanks

  • leoadmleoadm Member ✭✭
    Accepted Answer

    Update: Actually the problem was a refreshview containing a collectionview

  • RodSanfordRodSanford USMember

    Is this still an issue for anyone? Both accepted explanations above describe my scenario also...changing shells after a login and my first page has a collection view inside a refresh view. The app works fine in iOS and Android, but in UWP I get the null reference.

    System.NullReferenceException: Object reference not set to an instance of an object.
    at Xamarin.Forms.Platform.UWP.FormsGridView.OnApplyTemplate()
    at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
    at Xamarin.Forms.Platform.UWP.VisualElementRenderer2.MeasureOverride(Size availableSize) at Windows.UI.Xaml.UIElement.Measure(Size availableSize) at Xamarin.Forms.Platform.UWP.VisualElementRenderer2.MeasureOverride(Size availableSize)
    at Windows.UI.Xaml.UIElement.Measure(Size avail

  • DamianSuessDamianSuess USMember ✭✭✭

    @RodSanford, I too have the same thing with a CollectionView inside of a RefreshView. Is there a better way of handling this in our UWP apps?

       <RefreshView Command="{Binding CmdRefreshNews}" IsRefreshing="{Binding IsNewsRefreshing, Mode=OneWay}">
          <CollectionView x:Name="MyCollectionView"
                          ItemsSource="{Binding Mode=OneWay, Path=NewsArticles}"
                          SelectedItem="{Binding NewsItemSelected}"
                          SelectionChangedCommand="{Binding CmdNewsSelectionChanged}"
                          SelectionChangedCommandParameter="{Binding ., Source={x:Reference MyCollectionView}}"
                          SelectionMode="Single"
                          VerticalOptions="FillAndExpand">
    ...
    
Sign In or Register to comment.