Unexplained "The parameter is incorrect" error

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
I started getting a "The parameter is incorrect" error for some reason that I cannot figure out. When I do a debug, it takes me to the "Application_UnhandledException" method in App.xaml.vb. When I look at the Call Stack, I see:

> ScoreKeeperTest.dll!ScoreKeeperTest.App.Application_UnhandledException(Object sender = {ScoreKeeperTest.App}, System.Windows.ApplicationUnhandledExceptionEventArgs e = {System.Windows.ApplicationUnhandledExceptionEventArgs}) Line 65 + 0x5 bytes Basic
System.Windows.dll!MS.Internal.Error.CallApplicationUEHandler(System.Exception e = {"The parameter is incorrect. "}) + 0x30 bytes
System.Windows.dll!MS.Internal.Error.GetXresultForUserException(System.Exception ex = {"The parameter is incorrect. "}) + 0x54 bytes
System.Windows.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj = 132967360, System.IntPtr unmanagedObjArgs = 132936768, int argsTypeIndex = 160, string eventName = "M@36") + 0x165 bytes
[External Code]

Which does not mention any of my code, so it does not help me figure out what code of mine could be causing the problem. But if I step through the code, I don't get the error at all, so that obviously doesn't help me find where in my code, either. What is the problem, and why is it acting differently when I do a step through?
 

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
You're supposed to look at the call stack of the exception, which is provided to you in the 'e' parameter.
I posted the Call Stack in my original post, and as I said, it does not mention any of my code. Am I missing something?
 

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
Wrong call stack. Read what I posted.
Do you mean e.ExceptionObject.StackTrace? I guess I was a little confused because that was called StackTrace rather than call stack, but here is that:

at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
at System.Windows.UIElement.TransformToVisual(UIElement visual)
at System.Windows.Controls.SipHelper.AdjustFrame(FrameworkElement element, Double bottomMargin, Double& stillObscured)
at System.Windows.Controls.SipHelper.SelectionChanged(Object sender, RoutedEventArgs 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)

But just like the other one, it doesn't mention any of my code, so it isn't helping me any more. Any other suggestions? Thanks.
 

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
Then remove the UnhandledException event handler and let it crash. Hopefully that will point you to a more specific location.
Well, that didn't give me any more information, but I did eventually figure out a line that when commented out stops the error. Here is the section of code containing that line:
Private Sub Player_TextChanged(sender As Object, e As TextChangedEventArgs)
    If String.IsNullOrEmpty(CType(sender, Player).PlayerName) Then
        Dim index As Integer = Me.stkPlayers.Children.IndexOf(CType(sender, Player))
        If (index <> -1 AndAlso index <> Me.stkPlayers.Children.Count - 1) Then
            Me.stkPlayers.Children.RemoveAt(index)
            CType(Me.stkPlayers.Children(0), Player).IsFirstPlayer = True
        End If
    Else
        If (Not String.IsNullOrEmpty(CType(Me.stkPlayers.Children.Last(), Player).PlayerName)) Then Me.stkPlayers.Children.Add(Me.CreatePlayer())
    End If
End Sub

The above code will cause the "The parameter is incorrect" error as originally stated. However, if I comment out the following line, as follows:

'Me.stkPlayers.Children.RemoveAt(index)

Then it works with no problem (except, of course, for the fact that it does not do everything I want it to). What could I possibly be doing wrong here? Thanks.
 
Last edited by a moderator:
Top Bottom