Strange Slider-related crash post beta 2 (was working beta 1) RRS feed

  • Question

  •  I posted this earlier (somewhat mistakenly) in 'Silverlight Controls' forum

    Microsoft JScript runtime error: Unhandled Error in Silverlight 2 Application
    Code: 4004    
    Category: ManagedRuntimeError       
    Message: System.ArgumentException: Value does not fall within the expected range.
       at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.SetValue(IntPtr oPtr, UInt32 iPropertyId, Double d)
       at System.Windows.DependencyObject.SetValue(DependencyProperty property, Double d)
       at System.Windows.FrameworkElement.set_Height(Double value)
       at System.Windows.Controls.Slider.UpdateTrackLayout()
       at System.Windows.Controls.Slider.<.ctor>b__7(Object , SizeChangedEventArgs )
       at System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e)
       at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)    


    Here's the basic setup to get you started Big Smile.  I'll try to get some code or a reproable example up here soon:

    I have a "YouTube style" volume slider that's inside a little grid which animates into and out-of view when the user clicks a button. When it's "out of view" I collapse it after the animation is done. I also have two sliders on top of each other (one for the media timeline and one for media download progress).

    The volume slider "animates in" behind the timeline/download sliders.  The timeline slider is HitTestVisible--download isn't.

    Steps to repro:

    1. Load application.
    2. Click the timeline slider anywhere.  Crash: see above stack trace.

    Steps to "workaround":

    1. Load application.
    2. Click the volume button.
    3. When animation completes, drag volume slider.
    4. Click the timeline slider anywhere. No crash!

    Based on that stack trace, I tried removing any 'Height=' from my sliders (volume, timeline, and download). I also removed any custom templating styling I was doing to these controls.  Neither of these fixed the issue.

     Here's the xaml relevant to the sliders:

            <Grid x:Name="volumePopout" Visibility="Visible" Opacity="1" RenderTransformOrigin="0.5,0.5" Width="26" Height="69.5" HorizontalAlignment="Left" Margin="130.332992553711,-61,0,0" VerticalAlignment="Top">
                <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.7" Fill="#FFFFFFFF" RadiusX="5" RadiusY="5" x:Name="volumeBackground"/>
                <Slider HorizontalAlignment="Stretch" Margin="4,4,4,12" VerticalAlignment="Stretch" Orientation="Vertical" x:Name="sliderVolume"/>




    <Slider Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Maximum="1" x:Name="sliderDownload" Value="0" IsHitTestVisible="False" Height="5" Width="Auto" />
                <Slider Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Maximum="100" x:Name="sliderTimeline" Height="5" Width="Auto" />
                <Canvas Height="5" HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="timelineTrack" Grid.Row="0" />


    I include that last canvas because I do some layout "on top of" the sliders with it.  Yes, I've tried removing it and the problem persists...

    I'm stumped on this one.


    Other relevant info:

                    // Timeline Slider
                    this.sliderTimeline.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderTimeline_ValueChanged);
                    this.sliderTimeline.MouseLeftButtonDown += new MouseButtonEventHandler(sliderTimeline_MouseLeftButtonDown);
                    this.sliderTimeline.LargeChange = .01;
                    this.sliderTimeline.SmallChange = .01;
                    this.sliderTimeline.Maximum = 1;

                    // Volume Slider
                    this.sliderVolume.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderVolume_ValueChanged);
                    this.sliderVolume.LargeChange = .125;
                    this.sliderVolume.SmallChange = .125;
                    this.sliderVolume.Value = .5;


    It seems like clicking in the timeline slider tries to somehow "set" the value of the volume slider?  I should note that when you remove the volumeSlider, clicking in the timeline works fine.

    Tuesday, June 10, 2008 2:39 PM

All replies

  • Has anyone had a chance to look at this? 

    Wednesday, June 11, 2008 9:47 AM
  • The 'Value does not fall within the expected range' error is the new error message indicating that you don't have the targettype set or set to the correct property for one or more of your static resource styles. The 'Value' is the target type.

    Wednesday, June 11, 2008 9:51 AM
  •  I don't think that's the issue:

    1. I checked my whole app for every 'ControlTemplate' and 'Style'.  All had correct values of TargetType ("Button", "Slider", "RepeatButton", "Thumb", etc.).
    2. Everything works perfectly if you just open the volume slider BEFORE you click the timeline slider.  Something strange is going on with the activation/initialization of the volume slider if you happen to click ANY OTHER SLIDER first. Indeed--removing the volume slider clears up the crash.
    3. Take a closer look at the stack trace: it flows through System.Windows.FrameworkElement.set_Height(Double value) at System.Windows.Controls.Slider.UpdateTrackLayout()
    4. Remember, the volume control is initially Visibility.Collapsed but after a speaker button is clicked it's animated in from below (it's a vertically oriented slider, like YouTube). See #2.
    Thanks for your help.
    Wednesday, June 11, 2008 1:05 PM
  • So it crashes when the animation starts (#4)?

    Wednesday, June 11, 2008 1:15 PM
  • I wish it were that easy :D.  It has nothing to do with animation from what I can see.

    It crashes when you click on *ANOTHER* slider in the application BEFORE the "speaker" button is clicked.

    I set some breakpoints and the last thing that happens (as far as I can see) before the crash is the ValueChanged event is fired on the OTHER slider you click (not the volume slider, remember.  in this case it's my timeline slider I use for mediaelement progress).  My "timelineSlider_ValueChanged" EventHandler completes and then boom--crash.

    Wednesday, June 11, 2008 3:59 PM
  • O.K., I've got a solution which repro's this issue (it's not exactly my setup because there isn't a button to do the animation in/out of the slider).

    I'll post it in a second.

    I think the crash might have to do with the fact that I animate my volume popout "outside" of the boundaries of the control...is that a frowned upon practice? Angel

    Wednesday, June 11, 2008 4:14 PM
  • http://www.agilesports.com/files/SliderBug.zip 

    I'd appreciate if someone at MS looked at this.

    Launch it and click the timelineSlider anywhere to crash.

    Wednesday, June 11, 2008 4:34 PM
  • Figured out a workaround:

    In XAML, explicitly set Visibility = Visibility.Collapsed on the slider that's in the volumePopout grid (which itself IS explicitly set collapsed).  Then, before I animate in, set the slider to be visible.

    Is the 'Collapsed' property "propogated" to children correctly (at all?). Did this change since beta 1?

    Hope this helps anyone who's having any sort of similar issue...

    Wednesday, June 11, 2008 5:10 PM
  • Hello, your link points to an empty zip file. Can you please check it again?

    Thursday, June 12, 2008 6:15 AM
  • Fixed the link, Yi-Lun.

    Thanks for checking it out. 

    Thursday, June 12, 2008 9:40 AM
  • I am seeing a very similar error. When I set the value of a slider in code, it carshes (exception below). This used to work pre-beta 2. There is nothing fancy going on here. I have a slider in a property panel I created. When a user selects an object on teh canvas I enable the property panel that goes along with the object, then I set the controls (including teh slider) to the values of the object. When I walk through the code in the debugger, when I set the value of the slider (slider.Value), the slider's min is 0 and max is 200 and I am setting the value to 32.0, so that should be fine, but it blows up, and the weird part is that it doesn't always happen. It's related to me doing something before. It appears to be a bug to me.



        at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.SetValue(IntPtr oPtr, UInt32 iPropertyId, Double d)
       at System.Windows.DependencyObject.SetValue(DependencyProperty property, Double d)
       at System.Windows.FrameworkElement.set_Width(Double value)
       at System.Windows.Controls.Slider.UpdateTrackLayout()
       at System.Windows.Controls.Slider.OnValueChanged(Double oldValue, Double newValue)
       at System.Windows.Controls.Primitives.RangeBase.OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
       at System.Windows.DependencyObject.SetValue(DependencyProperty property, Double d)
       at System.Windows.Controls.Primitives.RangeBase.set_Value(Double value)
       at SilverlightClassLibrary1.RectTextPanel.setValuesFromControl()
       at SilverlightClassLibrary1.RectTextPanel.set_BoundControl(FrameworkElement value)
       at SilverlightApplication1.DesignerCanvas.updatePropPanel()
       at SilverlightApplication1.DesignerCanvas.addSelected(ISelectable item)
       at SilverlightClassLibrary1.RectTextControl.set_IsSelected(Boolean value)
       at SilverlightApplication1.MainPage.item_MouseLeftButtonUp(Object sender, MouseButtonEventArgs e)
       at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)


    Saturday, June 21, 2008 11:18 AM
  • Try setting the Visibility property on the slider itself to be 'Collapsed' and then explicitly set it to be 'Visible' when you "enable" the panel/slider (whatever you do when the user selects an object on the canvas). Make sure you are setting Visible/Collapsed on the parent elements properly as well.

    As far as I could tell in my instance, it was some sort of hit-test issue.  Your slider is probably getting hit tested when it's not in a proper state to do so (I think).


    Saturday, June 21, 2008 11:38 AM
  • This is a bug that was found too late for SL2b2. The problem is that behind the scenes, the ActualWidth and ActualHeight of the collapsed parts of the Scrollbar are getting set to infinity in layout. These values are then used in some scrollbar calculations to set the size of the thumb or something like that and setting Width=infinity will throw an exception.

     It will be fixed.

    Saturday, June 21, 2008 6:16 PM
  • Hello,

     I have an error that seems very similar to that of this bug, but I cannot seem to apply the workaround properly. Please see my post here: http://silverlight.net/forums/t/19657.aspx


    Tuesday, July 1, 2008 12:34 PM
  • Any ETA on the fix?  My project is also affected by this bug.

    Tuesday, July 29, 2008 12:16 PM
  • The app would crash trying to parse xaml where event added on slider control . Removing event from xaml and  adding "ValueChanged" event handler to the code after slider is loaded helped


    1    void MainPage_Loaded(object sender, RoutedEventArgs e)
    2            {
    3                slider.Loaded += new RoutedEventHandler(slider_Loaded);
    4            }
    6            void slider_Loaded(object sender, RoutedEventArgs e)
    7            {
    8                slider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(slider_ValueChanged);
    9            }
    11           void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
    12           {
    13               // TODO: Add event handler implementation here.;
    15           }
    Tuesday, June 29, 2010 5:15 PM