Fix IDE0025 (use expression body for properties)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / TypeInitializationException.cs
blob05d424f6a24cfd61634c72469e103dac95f428b6
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 /*=============================================================================
6 **
7 **
8 **
9 ** Purpose: The exception class to wrap exceptions thrown by
10 ** a type's class initializer (.cctor). This is sufficiently
11 ** distinct from a TypeLoadException, which means we couldn't
12 ** find the type.
15 =============================================================================*/
17 using System.Globalization;
18 using System.Runtime.Serialization;
20 namespace System
22 [Serializable]
23 [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
24 public sealed class TypeInitializationException : SystemException
26 private readonly string? _typeName;
28 // This exception is not creatable without specifying the
29 // inner exception.
30 private TypeInitializationException()
31 : base(SR.TypeInitialization_Default)
33 HResult = HResults.COR_E_TYPEINITIALIZATION;
37 public TypeInitializationException(string? fullTypeName, Exception? innerException)
38 : this(fullTypeName, SR.Format(SR.TypeInitialization_Type, fullTypeName), innerException)
42 // This is called from within the runtime. I believe this is necessary
43 // for Interop only, though it's not particularly useful.
44 internal TypeInitializationException(string? message) : base(message)
46 HResult = HResults.COR_E_TYPEINITIALIZATION;
49 internal TypeInitializationException(string? fullTypeName, string? message, Exception? innerException)
50 : base(message, innerException)
52 _typeName = fullTypeName;
53 HResult = HResults.COR_E_TYPEINITIALIZATION;
56 private TypeInitializationException(SerializationInfo info, StreamingContext context)
57 : base(info, context)
59 _typeName = info.GetString("TypeName");
62 public override void GetObjectData(SerializationInfo info, StreamingContext context)
64 base.GetObjectData(info, context);
65 info.AddValue("TypeName", TypeName, typeof(string));
68 public string TypeName => _typeName ?? string.Empty;