{"record":{"id":"e1261f87a773c5af","repo":"dotnet/wpf","slug":"rightsmanagementfailurecode-hr","errorCode":"(RightsManagementFailureCode)hr","errorMessage":"GetLocalizedFailureCodeMessage((RightsManagementFailureCode)hr) (localized message for failure code)","messagePattern":"GetLocalizedFailureCodeMessage\\(\\(RightsManagementFailureCode\\)hr\\) \\(localized message for failure code\\)","errorType":"error_code","errorClass":"MS.Internal.Security.RightsManagement.RightsManagementException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/Errors.cs","lineNumber":47,"sourceCode":"        /// Rights Management Failure code it will throw a RightsManagementException with an appropriate\n        /// message. Otherwise, if code isn't recognized as Rights Management specific,  it will throw\n        /// RightsManagementException which has a COMException as an inner exception with the\n        /// appropriate hr code.\n        /// </summary>\n        internal static void ThrowOnErrorCode(int hr)\n        {\n            // we can return if it is not a failure right away\n            // there is no reason to attempt to look-up codes and\n            // messages which is somewhat expensive in the case of success\n            if (hr >=0)\n            {\n                return;\n            }\n\n            string errorMessage = GetLocalizedFailureCodeMessage((RightsManagementFailureCode)hr);\n            if (errorMessage != null)\n            {\n                throw new RightsManagementException((RightsManagementFailureCode)hr, errorMessage);\n            }\n            else\n            {\n                try\n                {\n                    // It seems that ThrowExceptionForHR is the most consistent way\n                    // to get a platform representation of the unmanaged HR code\n                    Marshal.ThrowExceptionForHR(hr);\n                }\n                // We are re-throwing the same exception wrapped in a more specific message\n                catch (Exception e)\n                {\n                    // rethrow the exception as an inner exception of the RmExceptionGenericMessage\n                    throw new RightsManagementException(SR.RmExceptionGenericMessage, e);\n                }\n            }\n        }\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/Errors.cs#L29-L65","documentation":"Errors.ThrowOnErrorCode converts a native DRM HRESULT into a .NET exception. It first looks up a localized message for the RightsManagementFailureCode and throws RightsManagementException with that message; this entry represents that mapped failure for whatever failure code the native call returned.","triggerScenarios":"Any P/Invoke into the DRM SDK (DRMGetSignedIssuanceLicense, DRMCreateClientSession, license bind/acquire, etc.) returning a non-zero HRESULT that has a known localized failure-code message; the exception carries the corresponding RightsManagementFailureCode.","commonSituations":"RMS service connectivity failures, authentication failures against the AD RMS server, malformed license arguments passed to native APIs — all funneled here from many call sites.","solutions":["Read the RightsManagementException.FailureCode on the thrown exception to identify the exact native failure.","Check the inner DRM diagnostic logs / RMS server event log for the underlying cause.","Fix the inputs to the failing native call (handles, license XML, user IDs) per the failure code.","Catch RightsManagementException at the publish/consume boundary and map failure codes to user actions."],"exampleFix":"// before: generic catch loses the failure code\ncatch (Exception ex) { Log(ex.Message); }\n\n// after\ncatch (RightsManagementException ex)\n{\n    Log($\"RM failure {ex.FailureCode}: {ex.Message}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (RightsManagementException ex)\n{\n    switch (ex.FailureCode)\n    {\n        case RightsManagementFailureCode.ServerNotFound: /* check connectivity */ break;\n        default: Log(ex.FailureCode + \": \" + ex.Message); break;\n    }\n}","preventionTips":["Branch on RightsManagementException.FailureCode, not message text.","Validate handles and license XML before native calls so HRs stay in the documented set.","Monitor RMS server health; most mapped failure codes originate there."],"tags":["rights-management","drm","hresult","native-interop"],"backgroundTag":"native-call-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"}