none
PointerDownThemeAnimation crashing...

    Question

  • I have some fairly simple code that is in one of my Windows 8 applications.  However when I run the code on windows phone (universal application) I get a crash with a null reference exception even though the object that I am calling Begin() on is NOT null:

    Storyboard sb = new Storyboard();
    PointerDownThemeAnimation animation = new PointerDownThemeAnimation();
    Storyboard.SetTarget(animation, sender as FrameworkElement);
    sb.Children.Add(animation);
    sb.Begin();

    Exception is:
    System.NullReferenceException occurred
      _HResult=-2147467261
      _message=Object reference not set to an instance of an object.
      HResult=-2147467261
      IsTransient=false
      Message=Object reference not set to an instance of an object.
      InnerException:

    Why is it doing this when the code worked perfectly fine in windows 8?

    Thanks,
    Stefan

    Monday, April 21, 2014 11:08 PM

All replies

  • No idea Stefan,

    Please post a simplified sample of the problem on OneDrive or for personal 1 on 1 support open a support case.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Tuesday, April 22, 2014 7:04 PM
    Moderator
  • Sample at:

    http://1drv.ms/QvOlIS

    Click on the green border and it will crash

    Tuesday, April 22, 2014 8:20 PM
  • I was able to repro with this project, looks like the problem is somewhere inside the XAML engine ...a target property name is not getting set for some reason.

    Eric Fleck, Windows Store and Windows Phone Developer Support If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast your votes for existing suggestions.

    Wednesday, April 23, 2014 10:55 PM
  • Any news on the topic? This is still broken for universal apps.

    It works like a charm for Windows 8 but on the Phone it crashes...

    Monday, June 23, 2014 2:43 PM
  • I filed a bug on this issue but I don't have any estimate on when, or if, it will be fixed.


    Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast your votes for existing suggestions.

    Tuesday, June 24, 2014 7:31 PM
  • Hi Erik,

    thanks for the response.

    Is the bug filed internally or on connect?

    Best regards

    -Simon

    Wednesday, June 25, 2014 9:53 AM
  • I filed the bug directly to our internal database.

    Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast your votes for existing suggestions.

    Wednesday, June 25, 2014 1:53 PM
  • Got the same problem here.

    Any news?

    Thanks.

    Sunday, March 15, 2015 8:24 AM
  • No news, still not fixed.

    Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast your votes for existing suggestions.

    Monday, March 16, 2015 3:29 PM
  • Yes, I can confirm is still happening on Windows Phone 10 with a Windows Phone 8.1 app.  I can't test on a Windows Phone 10 UAP app because it won't allow the emulator to run within my Hyper-V session :-(
    Tuesday, March 24, 2015 11:48 PM
  • I had the same problem with very similar code in a Windows 10 UWA. I was able to solve it by;

    1. Ensuring the target item had a name set (or dynamically allocating a unique name at runtime if it doesn't). 

    2. Setting TargetName instead of target.

    3. Adding the storyboard to the target items resources. I used a specific string as the key, and I only create and add the storyboard if it doesn't exist in the targets resources already.

    If you don't refer to the target by name, OR if the animation isn't in part of the logical tree (so it can't find the target by name) it will fail with a null reference exception. Using name works, but only if the item is in the logical tree, hence adding it to the target items resources collection.

    Sample code;

    var fe = ((FrameworkElement)associatedObject);
    var name = fe.Name;
    if (String.IsNullOrEmpty(name))
    {
    name = Guid.NewGuid().ToString();
    fe.Name = name;
    }

    if (fe.Resources.ContainsKey("VisualTapDownAnimation"))
    _PointerDownStoryboard = (Storyboard)fe.Resources["VisualTapDownAnimation"];
    else
    {
    var pointerDownStoryboard = new Storyboard();
    var downAnimation = new PointerDownThemeAnimation();
    Storyboard.SetTargetName(downAnimation, name);
    pointerDownStoryboard.Children.Add(downAnimation);
    _PointerDownStoryboard = pointerDownStoryboard;
    fe.Resources.Add(new KeyValuePair<object, object>("VisualTapDownAnimation", pointerDownStoryboard));
    }

    Tuesday, June 30, 2015 9:25 AM