简体   繁体   中英

System.Printing.PrintQueueException: PrintTicket provider failed to bind to printer. Win32 error: Access is denied

I have an application where I want to print a Word document. I am using third party GemBox software, and in my development environment this code works;

public void OutputLetter(string outputFile, string placeholder, string newText)
{
    using (var document = DocX.Load(this.InputFile))
    {
        document.ReplaceText(placeholder, newText);
        document.SaveAs(outputFile);
    }

    this.PrintDocument(outputFile);
}

private void PrintDocument(string outputFile)
{
    var document = DocumentModel.Load(outputFile, LoadOptions.DocxDefault);
    document.Print(AppSettings.PrinterName);
}

AppSettings.PrinterName is the name of the printer stored in web.config. Once I deploy it, I get this error on the line; "document.Print(AppSettings.PrinterName);"

System.Printing.PrintQueueException: PrintTicket provider failed to bind to printer. Win32 error: Access is denied. 

On the event viewer I get;

The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID 
{BA7C0D29-81CA-4901-B450-634E20BB8C34}
 and APPID 
{AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0}
 to the user IIS APPPOOL\Mulalley SID (S-1-5-82-1744840036-3971326342-2272496405-1389653927-2904033151) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool.

How do I fix this?

This looks like it could be this issue Microsoft bk2872151

They provide a fix-it for users, the suggested solution for developers is to make sure you are not running in 32bit mode on a 64bit server (ie switch to AnyCPU).

Note that in VS2013 there is also an extra check box for prefer 32Bit even if you pick AnyCPU

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM