Page 1 of 1

AccessViolationException in System.Drawing.dll

Posted: Fri May 05, 2017 5:32 pm
by philip1978
We recently moved all our machines to GDPicture from - This resolved a couple of issues we were having previously but now we are encountering a new issue we have never encountered before.

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)
                    oGdPictureImaging.TiffAppendPageFromGdPictureImage(outputHandler, ImageID)
                End If
            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
                If delPage <= newPageCount Then
                    GdViewer1.DisplayPage(delPage - 1)
                End If
So, a user has a large pdf (say, 75 pages) open in the viewer, which is loaded in from oGdPictureImaging. They page through until they find a page to remove, hit a button, and the code removes that page and rebuilds the pdf before saving the new bytearray to the database, and reloading the pdf, now without our deleted page.

This code has a tendency to get stuck at the line:

Code: Select all

m_stat = oGdPictureImaging.TiffDeletePage(ImageID, GdViewer1.CurrentPage)
We were not having this issue while using

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.



Re: AccessViolationException in System.Drawing.dll

Posted: Fri May 05, 2017 8:40 pm
by philip1978
We resolved this issue, and it was unrelated to GdPicture, so apologies for gumming up the forum. Turned out to be an issue with target architecture and memory allocation. We changed over to the build of GdPicture at the same time we also changed a few other items. As a result we ended up having to change Assembly instructions in Visual Studio to allow Any CPU for the Platform, but target an x86 environment.

We ultimately ended up using a fix similar to the one here, if anyone else happens to come across the same issue: ... -installed

Again, so to post unnecessarily.

Re: AccessViolationException in System.Drawing.dll

Posted: Fri May 12, 2017 7:09 pm
by Loïc
Thank you very much for the update Philip! This post is not unnecessarily at all since it brings a resolution to a problem that can be encountered by others, thank you very much for that!



Re: AccessViolationException in System.Drawing.dll

Posted: Mon May 22, 2017 5:08 pm
by philip1978
So, apparently we spoke too soon. This is still happening, though less often. The information in my original post still applies, so any thoughts on how to troubleshoot would be helpful. When I try to debug, it ultimately takes me into assembly code and it won't let me see the code unless I turn off the option for "show only my code," so it would appear to be happening while executing gdpicture code.

Thanks in advance for any guidance.