Question

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

Was it helpful?

Solution

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

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
</startup>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top