Ok, heres the scenario, this is code that you'll see peppered in most of my
classes that utilize any kind of object that has a Dispose method
Dim conn as SqlConnection = MakeSqlConnection()
Try
' do some DB work
conn.Close()
Finally
' following line FAILS if conn is actually nothing
if not conn is Nothing then conn.Dispose()
' this works for some reason
if not conn is Nothing then
conn.Dispose()
end if
End try
---------------------------------
Private Shared Sub CropBitmap(ByVal sourceBitmap As System.Drawing.Bitmap,
ByVal destFilePath As String, ByVal region As System.Drawing.RectangleF)
Dim bitmap As System.Drawing.Bitmap
Dim croppedBitmap As System.Drawing.Bitmap
Dim hRes As Single = bitmap.HorizontalResolution
Dim vRes As Single = bitmap.VerticalResolution
Dim cropRegion As New System.Drawing.RectangleF(region.X * hRes, region.Y
* vRes, region.Width * hRes, region.Height * vRes)
Try
bitmap = sourceBitmap
croppedBitmap = bitmap.Clone(System.Drawing.Rectangle.Round(cropRe gion),
Drawing.Imaging.PixelFormat.Format1bppIndexed)
croppedBitmap.Save(destFilePath, System.Drawing.Imaging.ImageFormat.Tiff)
Finally
' ~~~~~~ this FAILS if croppedBitmap is actually nothing:
If Not croppedBitmap is Nothing then croppedBitmap.Dispose()
' ~~~~~~ this WORKS:
If Not croppedBitmap Is Nothing Then
croppedBitmap.Dispose()
End If
End Try
End Sub
--------------------------------
My hypothesis is that the VB compiler is getting into a slightly invalid
state once its hitting the Finally, and writing out incorrect IL code.
-------------------
Eric Newton
C#/ASP developer
er**@cc.ensoft-software.com [remove the first "cc."]