当我尝试在我的项目中运行代码分析时,我在这部分代码中遇到了错误。
//代码
Private Sub SaveMaterialStatus(ByVal status As String)
Dim cSMaterialInput As CSMaterialInput = Nothing
Try
If ViewState("CSInput") IsNot Nothing Then
'Create a new transaction
cSMaterialInput = New CSMaterialInput
cSMaterialInput = ViewState("CSInput")
cSMaterialInput.CSStatus = status
CSMaterialInputMethods.SaveToDatabase(cSMaterialInput, Environment.UserName, Environment.MachineName)
End If
Catch ex As Exception
Throw
Finally
If cSMaterialInput IsNot Nothing Then cSMaterialInput.Dispose()
End Try
End Sub
详细错误:
CA2000 Dispose objects before losing scope In method 'ShowSummary.SaveMaterialStatus(String)', call System.IDisposable.Dispose on object 'cSMaterialInput' before all references to it are out of scope. xxxx.CostingTool.Presentation ShowSummary.aspx.vb 790
我哪里错了??