Search code examples
c#printingfoxit

FoxIt PDF SDK - AccessViolationException in PrintWithDialog


Scenario: WinForms desktop app, .Net 2.0

We're having problems with 0.01% of our user base who are unable to print documents that we are presenting via FoxIt PDF SDK ActiveX v5.0.1

When the user clicks a "Print" button, we call the PrintWithDialog() method on the viewer control instance. At this point, an Access Violation Exception is thrown, and then the application hangs. The Print Dialog is not shown. No further user input (mouse, keyboard) brings it back to life and the process has to be killed via task manager.

The exception stack trace is:

AccessViolationException - Attempted to read or write protected memory. This is 
often an indication that other memory is corrupt.

   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at FoxitPDFSDKStdLib._DFoxitPDFSDK.PrintWithDialog()
   at AxFoxitPDFSDKStdLib.AxFoxitPDFSDK.PrintWithDialog()
   at MyCode.PDFToolBarButtonClick(Object sender, EventArgs e)

We cannot reproduce the problem, and FoxIt don't seem to be able to do anything to help us because we can't give them a project that reproduces the problem.

My suspicions are pointing towards Windows 7 and Group Policy control of print settings. We have had some success asking affected users to remove and reinstall the default printer, but then the problem resurfaces after a day or two. One site has policy settings controlling who can print in color, and installs the printer (the same physical device) differently.

Has anyone got any experience with Windows 7, or group policy settings, affecting printing?

EDIT: It's only FoxIt affected by this issue. Everything else - Acrobat, Word, Notepad etc prints without issue.


Solution

  • I can simulate this situation if I delete the default printer setting (meaning no printer set as default), so temporary renaming the following window registry key from "Device" to "OldDevice"

    HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device
    

    My simple form:

    public Form1()
    {
        InitializeComponent();
        try
        {
            this.axFoxitPDFSDK1.OpenFile(@"C:\foxit\FoxitPDFActiveX51_Manual.pdf", "");
    
           this.axFoxitPDFSDK1.PrintWithDialog();
        }
        catch (System.Exception exc)
        {
            Debug.WriteLine(exc.StackTrace);
            Debug.WriteLine(exc.Message);
            if (exc.InnerException != null)
            {
                Debug.WriteLine(exc.InnerException.Message);
            }
    
        }
    }
    

    and the relevant output from debug:

    Eccezione first-chance di tipo 'System.AccessViolationException' in mscorlib.dll
    'MySOfoxit.vshost.exe' (Gestito (v2.0.50727)): 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' caricato, caricamento simboli ignorato. Il modulo è ottimizzato e l'opzione 'Just My Code' del debugger è abilitata.
       in System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       in FoxitPDFSDKStdLib._DFoxitPDFSDK.PrintWithDialog()
       in AxFoxitPDFSDKStdLib.AxFoxitPDFSDK.PrintWithDialog()
       in MySOfoxit.Form1..ctor() in c:\foxit\MySOfoxit\Form1.cs:riga 23
    Tentativo di lettura o scrittura della memoria protetta. Spesso questa condizione indica che altre parti della memoria sono danneggiate.
    

    I can mention this link as (maybe) one of the possible causes of the triggering event. Other applications (WinWord, Adobe Reader) work as expected (only the manual selection of the printer is needed)