mscorlib error

  • Thread starter Thread starter BobG
  • Start date Start date
B

BobG

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim position As Integer = lstImages.SelectedIndex
Try

Dim FileToDelete As String

FileToDelete = PicPath & "\" & lstImages.SelectedItem

Dim iResult As DialogResult _
= MessageBox.Show("Delete " & FileToDelete & "?", _
"Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If iResult = DialogResult.Yes Then
pbEditBox.Image.Dispose()

File.Delete(FileToDelete)
MsgBox("File Deleted!")

lstImages.Items.RemoveAt(position)

lstImages.Refresh()
lstImages.Focus()

End If

Catch ex As Exception

MsgBox("Error :" & ex.Source & " " & ex.Message)
Finally
Throw New System.Exception("An exception has occurred.")

End Try
The above routine does what it was intended to do that is:
pbEditBox Picturebox showing the image.
lstIamges Name of the listbox.

1. Delete an image file from its current location.
2. Remove its name from the listbox

But it also throws the following error

' ERROR: mscorlib Value cannot be null. parameter Name:path'

Does anyone know what is causing this error?

Thanks
 
Dim FileToDelete As String

FileToDelete = PicPath & "\" & lstImages.SelectedItem

Dim iResult As DialogResult _
= MessageBox.Show("Delete " & FileToDelete & "?", _
"Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If iResult = DialogResult.Yes Then
pbEditBox.Image.Dispose()

File.Delete(FileToDelete)
[...]
But it also throws the following error

' ERROR: mscorlib Value cannot be null. parameter Name:path'

On which line does the exception occur? Is it the
'File.Delete(FileToDelete)' line? Did you already check the 'FileToDelete'
variable's value (although I do not see a reason why it should be
'Nothing')? What's the type of the exception that is being thrown?
 
Have you looked at the stack trace? Also, why would you throw an exception
in your Finally, since Finally always runs, you'll always throw an
exception?
 
Dim FileToDelete As String
FileToDelete = PicPath & "\" & lstImages.SelectedItem
Dim iResult As DialogResult _
= MessageBox.Show("Delete " & FileToDelete & "?", _
"Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If iResult = DialogResult.Yes Then
pbEditBox.Image.Dispose()
File.Delete(FileToDelete)
[...]
But it also throws the following error
' ERROR: mscorlib Value cannot be null. parameter Name:path'

On which line does the exception occur? Is it the
'File.Delete(FileToDelete)' line? Did you already check the 'FileToDelete'
variable's value (although I do not see a reason why it should be
'Nothing')? What's the type of the exception that is being thrown?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -

- Show quoted text -
I was just trying to stop error message from popping up. forget about
the following statement.
the error occurs when I execute the statement '
lstImages.Items.RemoveAt(position) '


Thanks
 
Have you looked at the stack trace? Also, why would you throw an exception
in your Finally, since Finally always runs, you'll always throw an
exception?


















- Show quoted text -

Know I have not.

Throw an Exception error was just an attempt on my part to stop the
message from popping on the screen. Forget about ir
the error occurs when I execute the statement '
lstImages.Items.RemoveAt(position) '

Thanks
 
Back
Top