2013-05-21 60 views
0

當在標籤之間切換時,無論何時在初始條目之後的任何一點輸入tabCurves控件,都會在行lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty)處引發System.IO.FileLoadException。這對我來說完全是莫名其妙的,因爲我有另一個子代碼(tabNURBS_Enter(...)),它具有幾乎相同的代碼,但不會拋出任何異常。無理由拋出System.IO.FileLoadException

這是怎麼回事?

代碼:


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 

基於阿德里安的評論下面,我決定去lstCurves_SelectedIndexChanged Snooping功能,並註釋掉所有代碼和減緩註釋掉各行,直到我發現了這個問題(以下黑體) 。


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 

KeyframesIList(Of Keyframe)類型實際上是返回EventList(Of T) Implements IList(Of T)類型的內部列表中強制轉換爲類型IList(Of Keyframe)的屬性。 EventList(Of T)是一個包裝器,當項目被添加,插入,刪除,即將被刪除,修改或列表被清除或即將被清除時拋出事件。

會造成我遇到的問題嗎?


下面是定義m_NIS和動畫曲線對象的相關文件。 Download

+0

您是否嘗試過在錯誤行設置一個斷點,步入事件處理程序調用?我不能說爲什麼(因爲我不知道),但我有過去的實例,Visual Studio的調試器沒有報告該行真正拋出異常。相反,它報告了發生異常的方法的調用。 – Adrian

+0

我不確定發生了什麼,但現在它突破第一個條目。我在'lstCurves_SelectedIndexChanged'的定義上有一個斷點,但調試器在它到達那個點之前就斷開了。 – radar33

+0

嘗試從調試菜單中選擇「刪除所有斷點」並重新設置。 – Adrian

回答

0

其次使用的app.config文件與推薦XML代碼的建議修正補充說:

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

儘管這解決了它,但我不確定它爲什麼決定全部代理突然間。 – radar33

相關問題