{"record":{"id":"1f30712c120293f8","repo":"dotnet/wpf","slug":"printconfig-provider-bindfail","errorCode":"PrintConfig.Provider.BindFail","errorMessage":"PrintConfig.Provider.BindFail","messagePattern":"PrintConfig\\.Provider\\.BindFail","errorType":"error_code","errorClass":"PrintQueueException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs","lineNumber":57,"sourceCode":"        /// Constructs a new PrintTicket provider instance for the given device.\n        /// </summary>\n        /// <param name=\"deviceName\">name of printer device the provider should be bound to</param>\n        /// <param name=\"maxVersion\">max schema version supported by client</param>\n        /// <param name=\"clientVersion\">schema version requested by client</param>\n        /// <exception cref=\"PrintQueueException\">\n        /// The FallbackPTProvider instance failed to bind to the specified printer.\n        /// </exception>\n        public FallbackPTProvider(string deviceName, int maxVersion, int clientVersion)\n        {\n            Toolbox.EmitEvent(EventTrace.Event.WClientDRXPTProviderStart);\n\n            // We are not doing late binding to the device here because we should\n            // indicate right away if there was an error in binding the provider\n            // to the device.  Doing late binding would mean that any instance\n            // method could throw a no such printer exception.\n            if (!UnsafeNativeMethods.OpenPrinterW(deviceName, out this._deviceHandle, new HandleRef(this, IntPtr.Zero)))\n            {\n                throw new PrintQueueException(Marshal.GetLastWin32Error(), \"PrintConfig.Provider.BindFail\", deviceName);\n            }\n\n            try\n            {\n                PRINTER_INFO_2 info = GetPrinterInfo2W();\n                this._deviceName = info.pPrinterName;\n                this._driverName = info.pDriverName;\n                this._portName = info.pPortName;\n                if (info.pDevMode != null)\n                {\n                    this._driverVersion = info.pDevMode.DriverVersion;\n                }\n            }\n            catch (Win32Exception win32Exception)\n            {\n                throw new PrintQueueException(win32Exception.ErrorCode, \"PrintConfig.Provider.BindFail\", deviceName, win32Exception);\n            }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs#L39-L75","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the deviceName matches an installed printer exactly (enumerate PrintQueue/InstalledPrinters and use that string).","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.","Reinstall/reconnect the printer or its driver, then retry.","Catch PrintQueueException and fall back to a default print ticket instead of hard-failing."],"exampleFix":"// before\nvar provider = new FallbackPTProvider(savedDeviceName, ...); // savedDeviceName may not exist\n// after\nif (new PrintQueue(new PrintServer(), savedDeviceName).Exists)\n{\n    var provider = new FallbackPTProvider(savedDeviceName, ...);\n}\nelse\n{\n    // fall back to default printer name\n}","handlingStrategy":"try-catch","validationCode":"bool printerExists = new PrintQueue(new PrintServer(), deviceName).Exists;","typeGuard":null,"tryCatchPattern":"catch (PrintQueueException ex) when (ex.Message.Contains(\"BindFail\")) { /* fall back to default printer or default print ticket */ }","preventionTips":["Resolve printer names from the installed-printer list, not cached config.","Check the Win32 error code for access vs not-found causes.","Reconnect network printers and refresh drivers before printing.","Implement a fallback to the default printer when binding fails."],"tags":["printconfig","printer","win32","device-binding","wpf"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}