{"record":{"id":"d8e719af002412da","repo":"dotnet/wpf","slug":"printconfig-provider-bindfail-d8e719","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/PTProvider.cs","lineNumber":165,"sourceCode":"        /// Printing components are not installed on the client\n        /// </exception>\n        public PTProvider(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            uint hResult = UnsafeNativeMethods.PTOpenProviderEx(deviceName,\n                                                             maxVersion,\n                                                             clientVersion,\n                                                             out _providerHandle,\n                                                             out _schemaVersion);\n\n            if (!PTUtility.IsSuccessCode(hResult))\n            {\n                throw new PrintQueueException((int)hResult, \"PrintConfig.Provider.BindFail\", deviceName);\n            }\n\n#if _DEBUG\n            if (_schemaVersion != clientVersion)\n            {\n                // PTOpenProviderEx() shouldn't succeed if it can't support the requested version.\n                throw new InvalidOperationException(\"_DEBUG: Client requested Print Schema version \" +\n                                                    clientVersion.ToString(CultureInfo.CurrentCulture) +\n                                                    \" doesn't match to provider Print Schema version \" +\n                                                    _schemaVersion.ToString(CultureInfo.CurrentCulture));\n            }\n#endif\n\n            // If succeeded, PTOpenProviderEx() function should ensure that a valid _providerHandle\n            // is returned and the returned schemaVersion is within valid range (i.e. no greater than maxVersion)\n            this._deviceName = deviceName;\n\n            this._thread = Thread.CurrentThread;","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs#L147-L183","documentation":"PTProvider's constructor calls the native PTOpenProviderEx and checks the returned HRESULT; when it is not a success code, it throws PrintQueueException with reason PrintConfig.Provider.BindFail. This means the managed print ticket provider could not bind to the unmanaged print ticket provider for the given device and schema version.","triggerScenarios":"new PTProvider(deviceName, clientVersion, serverName) where PTOpenProviderEx returns a failure HRESULT: driver without a print ticket provider DLL, wrong schema clientVersion, print spooler not running, or unreachable print server.","commonSituations":"Targeting a driver that predates PrintTicket support (pre-Vista drivers); downgraded/uninstalled driver; spooler (Spooler service) stopped; connecting to a remote print server that rejects the call; session-isolated drivers under RDP.","solutions":["Verify the printer driver supports Print Schema (XPSDrv / Vista+ class driver); switch to an XPSDrv-capable driver.","Ensure the Print Spooler service is running (net start spooler).","Confirm serverName and deviceName resolve to an existing queue; test with a local queue.","Check that the requested schema version is supported by the driver's PT provider.","Catch PrintQueueException and inspect the embedded HRESULT for the native failure code."],"exampleFix":"// before\nvar provider = new PTProvider(\"OldPS Printer\", clientVersion, serverName); // driver has no PT provider\n// after\nvar queue = new PrintQueue(new PrintServer(serverName), \"Microsoft XPS Document Writer\");\nvar provider = new PTProvider(queue.FullName, clientVersion, serverName);","handlingStrategy":"try-catch","validationCode":"using var spooler = new ServiceController(\"Spooler\");\nif (spooler.Status != ServiceControllerStatus.Running)\n    throw new InvalidOperationException(\"Print Spooler is not running.\");\nbool exists = new PrintServer().GetPrintQueues().Any(q => q.FullName == deviceName);","typeGuard":"static bool CanBind(string deviceName, PrintServer server) =>\n    !string.IsNullOrWhiteSpace(deviceName) &&\n    server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections })\n          .Any(q => q.FullName == deviceName);","tryCatchPattern":"try { provider = new PTProvider(deviceName, clientVersion, serverName); }\ncatch (PrintQueueException ex) when (ex.Message.Contains(\"PrintConfig.Provider.BindFail\"))\n{\n    // inspect ex.HResult; fall back to managed PrintQueue.GetPrintCapabilities path\n}","preventionTips":["Ensure the Print Spooler service is running before binding.","Use XPSDrv-capable drivers when print ticket support is required.","Resolve device names from PrintServer enumeration rather than user input."],"tags":["wpf","printing","native-interop","printqueue"],"backgroundTag":"module-init-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}