AccessViolationException in System.Drawing.dll

Discussions about image processing and document imaging.
Post Reply
philip1978
Posts: 13
Joined: Mon Sep 19, 2016 5:45 pm

AccessViolationException in System.Drawing.dll

Post by philip1978 » Fri May 05, 2017 5:32 pm

We recently moved all our machines to GDPicture 12.0.0.60 from 12.0.0.29 - 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)
                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
            
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 12.0.0.29

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

philip1978
Posts: 13
Joined: Mon Sep 19, 2016 5:45 pm

Re: AccessViolationException in System.Drawing.dll

Post by philip1978 » Fri May 05, 2017 8:40 pm

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 12.0.0.60 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:

http://stackoverflow.com/questions/1418 ... -installed

Again, so to post unnecessarily.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: AccessViolationException in System.Drawing.dll

Post by Loïc » Fri May 12, 2017 7:09 pm

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!

Cheers,

Loïc

philip1978
Posts: 13
Joined: Mon Sep 19, 2016 5:45 pm

Re: AccessViolationException in System.Drawing.dll

Post by philip1978 » Mon May 22, 2017 5:08 pm

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests