dotnet/wpf · error · MS.Internal.Security.RightsManagement.RightsManagementException

(RightsManagementFailureCode)hr

(RightsManagementFailureCode)hr

Error message

GetLocalizedFailureCodeMessage((RightsManagementFailureCode)hr) (localized message for failure code)

What it means

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.

Solutions

  1. Read the RightsManagementException.FailureCode on the thrown exception to identify the exact native failure.
  2. Check the inner DRM diagnostic logs / RMS server event log for the underlying cause.
  3. Fix the inputs to the failing native call (handles, license XML, user IDs) per the failure code.
  4. Catch RightsManagementException at the publish/consume boundary and map failure codes to user actions.

Example fix

// before: generic catch loses the failure code
catch (Exception ex) { Log(ex.Message); }

// after
catch (RightsManagementException ex)
{
    Log($"RM failure {ex.FailureCode}: {ex.Message}");
}
Defensive patterns

Strategy: try-catch

Try / catch

catch (RightsManagementException ex)
{
    switch (ex.FailureCode)
    {
        case RightsManagementFailureCode.ServerNotFound: /* check connectivity */ break;
        default: Log(ex.FailureCode + ": " + ex.Message); break;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/Errors.cs:47

        /// Rights Management Failure code it will throw a RightsManagementException with an appropriate
        /// message. Otherwise, if code isn't recognized as Rights Management specific,  it will throw
        /// RightsManagementException which has a COMException as an inner exception with the
        /// appropriate hr code.
        /// </summary>
        internal static void ThrowOnErrorCode(int hr)
        {
            // we can return if it is not a failure right away
            // there is no reason to attempt to look-up codes and
            // messages which is somewhat expensive in the case of success
            if (hr >=0)
            {
                return;
            }

            string errorMessage = GetLocalizedFailureCodeMessage((RightsManagementFailureCode)hr);
            if (errorMessage != null)
            {
                throw new RightsManagementException((RightsManagementFailureCode)hr, errorMessage);
            }
            else
            {
                try
                {
                    // It seems that ThrowExceptionForHR is the most consistent way
                    // to get a platform representation of the unmanaged HR code
                    Marshal.ThrowExceptionForHR(hr);
                }
                // We are re-throwing the same exception wrapped in a more specific message
                catch (Exception e)
                {
                    // rethrow the exception as an inner exception of the RmExceptionGenericMessage
                    throw new RightsManagementException(SR.RmExceptionGenericMessage, e);
                }
            }
        }

View on GitHub (pinned to 81131a70a4)