0

When switching between tabs, whenever I enter the tabCurves control at any point after the initial entry, a System.IO.FileLoadException is thrown at the line lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty). This is completely baffling to me, as I have another sub (tabNURBS_Enter(...)) that has nearly identical code, but does not throw any exceptions.

What is going on here?

Code:


Private Sub tabCurves_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCurves.Enter
    ' See if the tab enter event is marked to be supressed...
    If tabMain.Tag Is tabMain Then _
        Exit Sub

    With lstCurves.Items
        ' Remove old entries.
        .Clear()

        ' Add new curves.
        For I As Integer = 0 To m_NIS.Curves.Count - 1
            .Add(m_NIS.Curves(I).Name)
        Next I
    End With

    ' Update selection.
    lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty)
End Sub

Private Sub lstCurves_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCurves.SelectedIndexChanged
    If lstCurves.SelectedIndex = -1 Then
        ' Since no curve is selected, disable all UI controls except the add button.
        ' ### code snipped ###

        ' Reset fields.
        ' ### code snipped ###
    Else
        ' Since a curve is selected, enable all UI controls.
        ' ### code snipped ###

        ' Update the fields.
        ' ### code snipped ###

        ' Force update of slider.
        sldCURVKeyframes_ValueChanged(Nothing, EventArgs.Empty)
    End If
End Sub

Private Sub sldCURVKeyframes_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldCURVKeyframes.ValueChanged
    ' Enable\Disable controls depending upon whether the slider is enabled or not.
    ' ### code snipped ###
End Sub

Private Sub tabNURBS_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabNURBS.Enter
    ' See if the tab enter event is marked to be supressed...
    If tabMain.Tag Is tabMain Then _
        Exit Sub

    With lstNURBS.Items
        ' Remove old entries.
        .Clear()

        ' Add new curves.
        For I As Integer = 0 To m_NIS.BSplines.Count - 1
            .Add(m_NIS.BSplines(I).Name)
        Next I
    End With

    ' Update selection.
    lstNURBS_SelectedIndexChanged(Nothing, EventArgs.Empty)
End Sub

Private Sub lstNURBS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstNURBS.SelectedIndexChanged
    If lstNURBS.SelectedIndex = -1 Then
        ' Since no curve is selected, disable all UI controls except the add button.
        ' ### code snipped ###

        ' Reset fields.
        ' ### code snipped ###
    Else
        ' Since a curve is selected, enable all UI controls.
        ' ### code snipped ###

        ' Update the fields.
        ' ### code snipped ###

        ' Force update of sliders.
        sldNURBSCtlPoints_ValueChanged(Nothing, EventArgs.Empty)
        sldNURBSKnots_ValueChanged(Nothing, EventArgs.Empty)
    End If
End Sub

Private Sub sldNURBSCtlPoints_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldNURBSCtlPoints.ValueChanged
    ' Enable\Disable controls depending upon whether the slider is enabled or not.
    ' ### code snipped ###

    ' Update fields.
    ' ### code snipped ###
End Sub

Private Sub sldNURBSKnots_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldNURBSKnots.ValueChanged
    ' Enable\Disable controls depending upon whether the slider is enabled or not.
    ' ### code snipped ###

    ' Update fields.
    ' ### code snipped ###
End Sub

Based on Adrian's comment below, I decided to go snooping in lstCurves_SelectedIndexChanged and commented out all the code and slowing uncommented each line until I found the problem (in bold below).


Private Sub lstCurves_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCurves.SelectedIndexChanged
    If lstCurves.SelectedIndex = -1 Then
        ' Since no curve is selected, disable all UI controls except the add button.
        btnCURVRemove.Enabled = False
        btnCURVRename.Enabled = False

        ' Reset fields.
        txtCURVPreInfinity.Text = ""
        txtCURVPostInfinity.Text = ""

        sldCURVKeyframes.Enabled = False
        sldCURVKeyframes.Value = 0
        sldCURVKeyframes.Maximum = 0
    Else
        ' Since a curve is selected, enable all UI controls.
        btnCURVRemove.Enabled = True
        btnCURVRename.Enabled = True

        ' Update the fields.
        With m_NIS.Curves(lstCurves.SelectedIndex)
            txtCURVPreInfinity.Text = .PreInfinity
            txtCURVPostInfinity.Text = .PostInfinity
            sldCURVKeyframes.Enabled = True
            sldCURVKeyframes.Maximum = .Keyframes.Count - 1
            sldCURVKeyframes.Value = 0
        End With

        ' Force update of slider.
        sldCURVKeyframes_ValueChanged(Nothing, EventArgs.Empty)
    End If
End Sub

Keyframes is of type IList(Of Keyframe) which is actually a property that returns a cast of an internal list of type EventList(Of T) Implements IList(Of T) to type IList(Of Keyframe). EventList(Of T) is a wrapper that throws events when an item is added, inserted, removed, about to be removed, modified, or the list is cleared or about to be cleared.

Would that be causing the problems I'm experiencing?


Here's the relevant files that define m_NIS and the animation curve objects. Download

radar33
  • 45
  • 7
  • Have you tried setting a breakpoint on the error line and stepping into the event handler call? I can't say why (because I don't know) but I've had instances in the past where Visual Studio's debugger didn't report the line an exception was really thrown from. Instead, it reported the call to the method the exception happened in. – Adrian May 21 '13 at 06:40
  • I'm not sure what happened, but now it's breaking on first entry. I have a breakpoint on the definition for `lstCurves_SelectedIndexChanged`, but the debugger breaks before it gets to that point. – radar33 May 22 '13 at 21:36
  • Trying selecting "delete all breakpoints" from the debug menu and setting it again. – Adrian May 22 '13 at 21:55
  • I've added some information to the OP. – radar33 May 22 '13 at 22:12
  • From the code you've provided I assume you're doing WPF keyframe animation? Do you have all of the WPF libraries available? The `FileLoadException` should have a `FileName` property that will tell you which assembly it couldn't load. – Adrian May 22 '13 at 22:26
  • What is WPF? I guess if I have to ask, then no. – radar33 May 22 '13 at 22:32
  • The FileName property is set to **Nothing**. – radar33 May 22 '13 at 23:31
  • Also, I've discovered the problem lies in the `AnimationCurve` class, specifically with the event handler code: `Private Sub Keyframes_Sort()` – radar33 May 22 '13 at 23:36

1 Answers1

0

Followed the advised fix of using app.config files with the recommended xml code added:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
</startup>
radar33
  • 45
  • 7