We get an unhandled AccessViolationException in System.Drawing.dll - Attempted to read or write protected memory. This is often an indication that other memory is corrupt. - that appears to happen at random intervals when calling gdPictureImaging.TiffDeletePage.
We use the following code to remove a page from a pdf:
Code: Select all
Dim newPageCount As Integer
Dim faxID As String
Dim m_stat As GdPicture12.GdPictureStatus
Dim outputHandler As Long
Dim delPage As Integer
If GdViewer1.PageCount > 1 Then
delPage = GdViewer1.CurrentPage
m_stat = oGdPictureImaging.TiffDeletePage(ImageID, GdViewer1.CurrentPage)
newPageCount = oGdPictureImaging.GetPageCount(ImageID)
For i As Integer = 1 To newPageCount
oGdPictureImaging.TiffSelectPage(ImageID, i)
If i = 1 Then
outputHandler = oGdPictureImaging.TiffCreateMultiPageFromGdPictureImage(ImageID)
Else
oGdPictureImaging.TiffAppendPageFromGdPictureImage(outputHandler, ImageID)
End If
Next
Dim ImageBytes As Byte() = Nothing
Dim Length As Integer
oGdPictureImaging.SaveAsByteArray(outputHandler, ImageBytes, Length, GdPicture12.DocumentFormat.DocumentFormatTIFF, 4)
faxID = vwFaxes.GetFocusedRowCellValue(ID)
Dim connection As SqlConnection = clsAdvancedDB.GetConnection
... 'Update Database
GdViewer1.CloseDocument()
GdViewer1.DisplayFromGdPictureImage(ImageID)
If delPage <= newPageCount Then
'GdViewer1.Redraw()
GdViewer1.DisplayPage(delPage)
Else
GdViewer1.DisplayPage(delPage - 1)
End If
This code has a tendency to get stuck at the line:
Code: Select all
m_stat = oGdPictureImaging.TiffDeletePage(ImageID, GdViewer1.CurrentPage)
I am happy to provide more information if necessary, as I can, but I wanted to see if this triggered any thoughts on its own.
Thanks!
Philip