无理由抛出System.IO.FileLoadException

时间:2013-05-21 03:31:30

标签: vb.net fileloadexception

在标签之间切换时,每当我在初始输入后的任何时刻输入tabCurves控件时,System.IO.FileLoadException都会在lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty)行处抛出。这对我来说完全是令人困惑的,因为我有另一个子代码(tabNURBS_Enter(...))具有几乎相同的代码,但不会抛出任何异常。

这里发生了什么?

代码:


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

根据Adrian在下面的评论,我决定在lstCurves_SelectedIndexChanged中进行窥探并注释掉所有代码并减慢每行的注释,直到找到问题为止(下面以粗体显示)。


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的类型为IList(Of Keyframe),它实际上是一个属性,它将类型EventList(Of T) Implements IList(Of T)的内部列表的强制转换返回到IList(Of Keyframe)类型。 EventList(Of T)是一个包装器,在添加,插入,删除,即将删除,修改项目或清除或即将清除列表时抛出事件。

这会导致我遇到的问题吗?


这是定义m_NIS和动画曲线对象的相关文件。 Download

1 个答案:

答案 0 :(得分:0)

遵循建议的修复使用app.config文件并添加了推荐的xml代码:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
</startup>