dotnet/wpf · error · PrintQueueException

PrintConfig.Provider.BindFail

PrintConfig.Provider.BindFail

Error message

PrintConfig.Provider.BindFail

What it means

FallbackPTProvider's constructor immediately binds to the print device via UnsafeNativeMethods.OpenPrinterW. If OpenPrinterW fails, it throws PrintQueueException with code "PrintConfig.Provider.BindFail" carrying the Win32 error from GetLastError and the device name, so binding errors surface right away instead of failing later on instance methods.

Solutions

  1. Verify the deviceName matches an installed printer exactly (enumerate PrintQueue/InstalledPrinters and use that string).
  2. Check the Win32 error code in the exception: 0x7 (ERROR_FILE_NOT_FOUND) means the printer name is wrong; 0x5 (ACCESS_DENIED) means permissions; network errors mean the print server is unreachable.
  3. Reinstall/reconnect the printer or its driver, then retry.
  4. Catch PrintQueueException and fall back to a default print ticket instead of hard-failing.

Example fix

// before
var provider = new FallbackPTProvider(savedDeviceName, ...); // savedDeviceName may not exist
// after
if (new PrintQueue(new PrintServer(), savedDeviceName).Exists)
{
    var provider = new FallbackPTProvider(savedDeviceName, ...);
}
else
{
    // fall back to default printer name
}
Defensive patterns

Strategy: try-catch

Validate before calling

bool printerExists = new PrintQueue(new PrintServer(), deviceName).Exists;

Try / catch

catch (PrintQueueException ex) when (ex.Message.Contains("BindFail")) { /* fall back to default printer or default print ticket */ }

Prevention

When it happens

Trigger: Constructing a FallbackPTProvider with a deviceName that OpenPrinterW cannot open: printer name misspelled or no longer installed, printer offline/deleted, no permission to access the printer, or the printer connection unavailable (network print server down).

Common situations: Renamed or removed printers after a config file cached the old name; terminal-server/redirected printer sessions; missing printer driver; insufficient user permissions on a shared network printer.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/1f30712c120293f8. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs:57

        /// Constructs a new PrintTicket provider instance for the given device.
        /// </summary>
        /// <param name="deviceName">name of printer device the provider should be bound to</param>
        /// <param name="maxVersion">max schema version supported by client</param>
        /// <param name="clientVersion">schema version requested by client</param>
        /// <exception cref="PrintQueueException">
        /// The FallbackPTProvider instance failed to bind to the specified printer.
        /// </exception>
        public FallbackPTProvider(string deviceName, int maxVersion, int clientVersion)
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXPTProviderStart);

            // We are not doing late binding to the device here because we should
            // indicate right away if there was an error in binding the provider
            // to the device.  Doing late binding would mean that any instance
            // method could throw a no such printer exception.
            if (!UnsafeNativeMethods.OpenPrinterW(deviceName, out this._deviceHandle, new HandleRef(this, IntPtr.Zero)))
            {
                throw new PrintQueueException(Marshal.GetLastWin32Error(), "PrintConfig.Provider.BindFail", deviceName);
            }

            try
            {
                PRINTER_INFO_2 info = GetPrinterInfo2W();
                this._deviceName = info.pPrinterName;
                this._driverName = info.pDriverName;
                this._portName = info.pPortName;
                if (info.pDevMode != null)
                {
                    this._driverVersion = info.pDevMode.DriverVersion;
                }
            }
            catch (Win32Exception win32Exception)
            {
                throw new PrintQueueException(win32Exception.ErrorCode, "PrintConfig.Provider.BindFail", deviceName, win32Exception);
            }

View on GitHub (pinned to 81131a70a4)