question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transitioner NullReference

See original GitHub issue

Using 2.3.1 version: Randomly when dragging a new control (grid, listbox, textbox, button, doesn’t matter) onto my form a nullreference exception in the designer occurs. I don’t drag the controls on the transitioner, it’s just enough for it to be on my application at all.

Actually the issue happens randomly but quite often. Happens when dragging controls on designer, happens when exiting from debugging. Happens when controls in designer get changed.

NullReferenceException: Object reference not set to an instance of an object.

 at MaterialDesignThemes.Wpf.Transitions.Transitioner.ActivateFrame(Int32 selectedIndex, Int32 unselectedIndex)
   at MaterialDesignThemes.Wpf.Transitions.Transitioner.<.ctor>b__14_0(Object sender, RoutedEventArgs args)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
olegsaveloscommented, Apr 5, 2019

Yes on latest build, the exception happens here

  private void ActivateFrame(int selectedIndex, int unselectedIndex)
        {
            if (!IsLoaded) return;

            TransitionerSlide oldSlide = null, newSlide = null;
            for (var index = 0; index < Items.Count; index++)
            {
                var slide = GetSlide(Items[index]);
                if (index == selectedIndex)
                {
                    newSlide = slide;
                    slide.SetCurrentValue(TransitionerSlide.StateProperty, TransitionerSlideState.Current);
                }
                else if (index == unselectedIndex)
                {
                    oldSlide = slide;
                    slide.SetCurrentValue(TransitionerSlide.StateProperty, TransitionerSlideState.Previous);
                }
                else
                {
                    slide.SetCurrentValue(TransitionerSlide.StateProperty, TransitionerSlideState.None);
                }
                Panel.SetZIndex(slide, 0);
            }

            if (newSlide != null)
            {
                newSlide.Opacity = 1;
            }

            if (oldSlide != null && newSlide != null)
            {
                var wipe = selectedIndex > unselectedIndex ? oldSlide.ForwardWipe : oldSlide.BackwardWipe;
                if (wipe != null)
                {
                    wipe.Wipe(oldSlide, newSlide, GetTransitionOrigin(newSlide), this);
                }
                else
                {
                    DoStack(newSlide, oldSlide);
                }

                oldSlide.Opacity = 0;
            }
            else if (oldSlide != null || newSlide != null)
            {
                DoStack(oldSlide ?? newSlide);
                if (oldSlide != null)
                {
                    oldSlide.Opacity = 0;
                }
            }

            _nextTransitionOrigin = null;
        }

when calling

   private TransitionerSlide GetSlide(object item)
        {
            if (IsItemItsOwnContainer(item))
                return (TransitionerSlide)item;

            return (TransitionerSlide)ItemContainerGenerator.ContainerFromItem(item);
        }

My first thought was Virtualization but even when i tried an non-virtualized panel the effect was the same.

Here is the xaml

     <md:Transitioner Grid.Row="1"
                                         SelectedItem="{Binding SelectedItem}"
                                         ItemsSource="{Binding ItemsView}">
                            <md:Transitioner.Resources>
                                <Style TargetType="md:TransitionerSlide" BasedOn="{StaticResource {x:Type md:TransitionerSlide}}">
                                    <Setter Property="BackwardWipe">
                                        <Setter.Value>
                                            <md:FadeWipe Duration="0:0:0.5" />
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="ForwardWipe">
                                        <Setter.Value>
                                            <md:FadeWipe Duration="0:0:0.5" />
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </md:Transitioner.Resources>
                            <md:Transitioner.ItemTemplate>
                                <DataTemplate>
                                    <ContentControl Content="{Binding Module.View}" />
                                </DataTemplate>
                            </md:Transitioner.ItemTemplate>
                        </md:Transitioner>
0reactions
Keboocommented, Apr 26, 2019

Fixed by #1242

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with Legend of Zelda like screen transition getting ...
A null reference exception basically means that a variable of reference type contains nothing, but you try to access something inside of it, ......
Read more >
Null Reference Exceptions
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable isn't referencing an ......
Read more >
Null References: The Billion Dollar Mistake - InfoQ
Tony Hoare introduced Null references in ALGOL W back in 1965 "simply because it was so easy to implement", says Mr. Hoare.
Read more >
reactjs - Undefined/null reference when trying to add ...
I managed to get this to work by adding the react-global and react-addons-transition-group typings, the generated typings file now includes ...
Read more >
This is how you get rid of null reference exceptions forever
https://aka.ms/nullable-blog In this episode, Rich sits down with Immo to explore how the new new nullable reference types feature works for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found