// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; namespace System { /// <summary> /// The exception that is thrown for invalid casting or explicit conversion. /// </summary> [Serializable] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class InvalidCastException : SystemException { public InvalidCastException() : base(SR.Arg_InvalidCastException) { HResult = HResults.COR_E_INVALIDCAST; } public InvalidCastException(string? message) : base(message ?? SR.Arg_InvalidCastException) { HResult = HResults.COR_E_INVALIDCAST; } public InvalidCastException(string? message, Exception? innerException) : base(message ?? SR.Arg_InvalidCastException, innerException) { HResult = HResults.COR_E_INVALIDCAST; } public InvalidCastException(string? message, int errorCode) : base(message ?? SR.Arg_InvalidCastException) { HResult = errorCode; } [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] [EditorBrowsable(EditorBrowsableState.Never)] protected InvalidCastException(SerializationInfo info, StreamingContext context) : base(info, context) { } } }