The Media Center Sandbox

Resources and discussion for developing experiences in the Windows Media Center platform.
Welcome to The Media Center Sandbox Sign in | Join | Help
in Search

ScrollingData.Scroll --> InvalidOperationException: Nullable object must have a value?!

Last post 07-05-2008, 5:37 AM by AndyC. 3 replies.
Sort Posts: Previous Next
  •  06-22-2008, 11:31 AM 7749

    ScrollingData.Scroll --> InvalidOperationException: Nullable object must have a value?!

    This is a weird one, which doesn't reproduce consistently.

    I have a Repeater/Scroller displaying data from a Choice. This data is loaded into memory before the page is displayed, so all should be fine there. As part of the data-load operation I set the .DefaultIndex property of the Choice to a value (depending on various flags in the data). If for some reason, at the end of the load operation this value is null or -1 it's set to 0.

    Then in my MCML I have code like this (the very basics really);

    <Default Target="[ScrollingHandler.ScrollingData]" Value="[ScrollingData]"/>
    <
    Default Target="[ScrollingData.Repeater]" Value="[ImgRepeater]"/>
    <
    Binding Source="[Choice.Options]" Target="[ImgRepeater.Source]"/>

    and this (which is invoked a quarter of a second after the page is displayed);

    <Changed Source="[SelIdx.Tick]">
      <!--
    <Conditions>
        <Equality Source="[Choice.DefaultIndex]" ConditionOp="GreaterThan" Value="0" />
      </Conditions>
    -->
      <
    Actions>
        <
    Invoke Target="[ScrollingData.Scroll]" amount="[Choice.DefaultIndex]"/>
      </
    Actions>
    </
    Changed>

    At times this works wonders, and the scroller is automatically moved to the "correct" item upon load, at other times it stays put on the first item in the list (this is due to the Timer.Interval I have found - if I make it larger, it takes longer to display the page, but the correct item is always selected) and again at other times it will throw a hissyfit and come up with an InvalidOperationException.

    The entire errormessage is;

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Nullable object must have a value.
      at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
      at Microsoft.MediaCenter.UI.ScrollingData.FocusBasedScrollingStrategy.Scroll(Int32 amount)
      at Microsoft.MediaCenter.UI.ScrollingData.Scroll(Int32 amount)

    so my initial thought was that for some reason Choice.DefaultIndex was not set properly, although stepping through the code (too many times to count - to be able to catch this exception in the first place) the value is ALWAYS correct as based on the data itself.

    Then I found it would throw an exception if it tried ScrollingData.Scroll(0) hence I added the Condition in the rule above. This resolved the issue when DefaultIndex was 0, but it still happens from time to time where the value is between 0 and the maximum number of entries in Choice.Options.

    I've just pulled out the last few strands of hair and would appreciate any input you may have on this. Even if it involves opening my window and throwing the computer out :D

  •  06-22-2008, 11:12 PM 7754 in reply to 7749

    Re: ScrollingData.Scroll --> InvalidOperationException: Nullable object must have a value?!

    Where does the load operation occur?  Is in prior to the page being rendered or afterward? Also, is it on the UI thread?

    Cheers,
    Andrew

  •  07-04-2008, 5:15 PM 7844 in reply to 7754

    Re: ScrollingData.Scroll --> InvalidOperationException: Nullable object must have a value?!

    Sorry for late reply - lightning can cause problems.

    But yes, the load operation is done before the page is rendered. Basically, when a user decides to go to this page he presses a button, this button has a command with a Event attached, which loads up the data before issuing GoToPage. All this happens on the UI thread, and I'm not sure what or where the problem is.

    I thought perhaps the page was trying to be rendered to quickly after loading the data (even though it happens on one thread) so added a thread.sleep between loading the data and rendering the page - same problem.

  •  07-05-2008, 5:37 AM 7845 in reply to 7844

    Re: ScrollingData.Scroll --> InvalidOperationException: Nullable object must have a value?!

    Couple  of things - you mention that DefaultIndex could be null, -1, or 0... do you have your own class derived from Choice, as DefaultIndex is an Int32 which should be possible to be null.

    Second thought, have you tried using ChosenIndex rather than DefaultIndex, or invoking DefaultValue in your constructor?

    Cheers,
    Andrew

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems