Table of Contents

Class MsalException

Namespace
Microsoft.Identity.Client
Assembly
Microsoft.Identity.Client.dll

Base exception type thrown when an error occurs during token acquisition. For more details, see https://aka.ms/msal-net-exceptions

public class MsalException : Exception, ISerializable
Inheritance
MsalException
Implements
Derived
Inherited Members

Remarks

Avoid throwing this exception. Instead throw the more specialized MsalClientException or MsalServiceException

Constructors

MsalException()

Initializes a new instance of the exception class.

public MsalException()

MsalException(string)

Initializes a new instance of the exception class with a specified error code.

public MsalException(string errorCode)

Parameters

errorCode string

The error code returned by the service or generated by the client. This is the code you can rely on for exception handling.

MsalException(string, string)

Initializes a new instance of the exception class with a specified error code and error message.

public MsalException(string errorCode, string errorMessage)

Parameters

errorCode string

The error code returned by the service or generated by the client. This is the code you can rely on for exception handling.

errorMessage string

The error message that explains the reason for the exception.

MsalException(string, string, Exception)

Initializes a new instance of the exception class with a specified error code and a reference to the inner exception that is the cause of this exception.

public MsalException(string errorCode, string errorMessage, Exception innerException)

Parameters

errorCode string

The error code returned by the service or generated by the client. This is the code you can rely on for exception handling.

errorMessage string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception, or a null reference if no inner exception is specified.

Fields

BrokerErrorCode

An AdditionalExceptionData property key, available when using desktop brokers.

public const string BrokerErrorCode = "BrokerErrorCode"

Field Value

string

BrokerErrorContext

An AdditionalExceptionData property key, available when using desktop brokers.

public const string BrokerErrorContext = "BrokerErrorContext"

Field Value

string

BrokerErrorStatus

An AdditionalExceptionData property key, available when using desktop brokers.

public const string BrokerErrorStatus = "BrokerErrorStatus"

Field Value

string

BrokerErrorTag

An AdditionalExceptionData property key, available when using desktop brokers.

public const string BrokerErrorTag = "BrokerErrorTag"

Field Value

string

BrokerTelemetry

An AdditionalExceptionData property key, available when using desktop brokers.

public const string BrokerTelemetry = "BrokerTelemetry"

Field Value

string

ManagedIdentitySource

An AdditionalExceptionData property key, available when using managed identity.

public const string ManagedIdentitySource = "ManagedIdentitySource"

Field Value

string

Properties

AdditionalExceptionData

A property bag with extra details for this exception.

public IReadOnlyDictionary<string, string> AdditionalExceptionData { get; set; }

Property Value

IReadOnlyDictionary<string, string>

CorrelationId

An ID that can used to piece up a single authentication flow.

public string CorrelationId { get; set; }

Property Value

string

ErrorCode

Gets the protocol error code returned by the service or generated by the client. This is the code you can rely on for exception handling. Values for this code are typically provided in constant strings in the derived exceptions types with explanations of mitigation.

public string ErrorCode { get; }

Property Value

string

IsRetryable

Indicates if the previous operation that resulted in this exception should be retried.

public bool IsRetryable { get; set; }

Property Value

bool

Methods

FromJsonString(string)

Allows re-hydration of the MsalException (or one of its derived types) from JSON generated by ToJsonString().

public static MsalException FromJsonString(string json)

Parameters

json string

Returns

MsalException

ToJsonString()

Allows serialization of most values of the exception into JSON.

public string ToJsonString()

Returns

string

ToString()

Creates and returns a string representation of the current exception.

public override string ToString()

Returns

string

A string representation of the current exception.