diff options
5 files changed, 122 insertions, 136 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index 384babf674..536977169d 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -261,7 +261,7 @@ <Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.CoreCLR.cs" /> <Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" /> <Compile Include="$(BclSourcesRoot)\System\TypedReference.cs" /> - <Compile Include="$(BclSourcesRoot)\System\TypeLoadException.cs" /> + <Compile Include="$(BclSourcesRoot)\System\TypeLoadException.CoreCLR.cs" /> <Compile Include="$(BclSourcesRoot)\System\TypeNameParser.cs" /> <Compile Include="$(BclSourcesRoot)\System\ValueType.cs" /> <Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" /> diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 91b6527b25..e8baac9747 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -886,6 +886,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\TypeAccessException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\TypeCode.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\TypeInitializationException.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\TypeLoadException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\TypeUnloadedException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\UInt16.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\UInt32.cs" /> diff --git a/src/System.Private.CoreLib/shared/System/TypeLoadException.cs b/src/System.Private.CoreLib/shared/System/TypeLoadException.cs new file mode 100644 index 0000000000..e884faa5ce --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/TypeLoadException.cs @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.Serialization; + +namespace System +{ + [Serializable] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + public partial class TypeLoadException : SystemException, ISerializable + { + public TypeLoadException() + : base(SR.Arg_TypeLoadException) + { + HResult = HResults.COR_E_TYPELOAD; + } + + public TypeLoadException(string message) + : base(message) + { + HResult = HResults.COR_E_TYPELOAD; + } + + public TypeLoadException(string message, Exception inner) + : base(message, inner) + { + HResult = HResults.COR_E_TYPELOAD; + } + + public override string Message + { + get + { + SetMessageField(); + return _message; + } + } + + public string TypeName => _className ?? string.Empty; + + protected TypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) + { + _className = info.GetString("TypeLoadClassName"); + _assemblyName = info.GetString("TypeLoadAssemblyName"); + _messageArg = info.GetString("TypeLoadMessageArg"); + _resourceId = info.GetInt32("TypeLoadResourceID"); + } + + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("TypeLoadClassName", _className, typeof(string)); + info.AddValue("TypeLoadAssemblyName", _assemblyName, typeof(string)); + info.AddValue("TypeLoadMessageArg", _messageArg, typeof(string)); + info.AddValue("TypeLoadResourceID", _resourceId); + } + + // If ClassName != null, GetMessage will construct on the fly using it + // and ResourceId (mscorrc.dll). This allows customization of the + // class name format depending on the language environment. + private string _className; + private string _assemblyName; + private readonly string _messageArg; + private readonly int _resourceId; + } +} diff --git a/src/System.Private.CoreLib/src/System/TypeLoadException.CoreCLR.cs b/src/System.Private.CoreLib/src/System/TypeLoadException.CoreCLR.cs new file mode 100644 index 0000000000..729e119773 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/TypeLoadException.CoreCLR.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; + +namespace System +{ + public partial class TypeLoadException : SystemException + { + // This is called from inside the EE. + private TypeLoadException(string className, + string assemblyName, + string messageArg, + int resourceId) + : base(null) + { + HResult = HResults.COR_E_TYPELOAD; + _className = className; + _assemblyName = assemblyName; + _messageArg = messageArg; + _resourceId = resourceId; + + // Set the _message field eagerly; debuggers look at this field to + // display error info. They don't call the Message property. + SetMessageField(); + } + + private void SetMessageField() + { + if (_message == null) + { + if (_className == null && _resourceId == 0) + _message = SR.Arg_TypeLoadException; + else + { + if (_assemblyName == null) + _assemblyName = SR.IO_UnknownFileName; + if (_className == null) + _className = SR.IO_UnknownFileName; + + string format = null; + GetTypeLoadExceptionMessage(_resourceId, JitHelpers.GetStringHandleOnStack(ref format)); + _message = string.Format(format, _className, _assemblyName, _messageArg); + } + } + } + + [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] + private static extern void GetTypeLoadExceptionMessage(int resourceId, StringHandleOnStack retString); + } +} diff --git a/src/System.Private.CoreLib/src/System/TypeLoadException.cs b/src/System.Private.CoreLib/src/System/TypeLoadException.cs deleted file mode 100644 index ff0b972414..0000000000 --- a/src/System.Private.CoreLib/src/System/TypeLoadException.cs +++ /dev/null @@ -1,135 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================================= -** -** -** -** Purpose: The exception class for type loading failures. -** -** -=============================================================================*/ - -using System; -using System.Globalization; -using System.Runtime.Serialization; -using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; -using System.Runtime.Versioning; -using System.Security; -using System.Diagnostics.Contracts; - -namespace System -{ - [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public class TypeLoadException : SystemException, ISerializable - { - public TypeLoadException() - : base(SR.Arg_TypeLoadException) - { - HResult = HResults.COR_E_TYPELOAD; - } - - public TypeLoadException(string message) - : base(message) - { - HResult = HResults.COR_E_TYPELOAD; - } - - public TypeLoadException(string message, Exception inner) - : base(message, inner) - { - HResult = HResults.COR_E_TYPELOAD; - } - - public override string Message - { - get - { - SetMessageField(); - return _message; - } - } - - private void SetMessageField() - { - if (_message == null) - { - if ((ClassName == null) && - (ResourceId == 0)) - _message = SR.Arg_TypeLoadException; - - else - { - if (AssemblyName == null) - AssemblyName = SR.IO_UnknownFileName; - if (ClassName == null) - ClassName = SR.IO_UnknownFileName; - - string format = null; - GetTypeLoadExceptionMessage(ResourceId, JitHelpers.GetStringHandleOnStack(ref format)); - _message = string.Format(format, ClassName, AssemblyName, MessageArg); - } - } - } - - public string TypeName - { - get - { - if (ClassName == null) - return string.Empty; - - return ClassName; - } - } - - // This is called from inside the EE. - private TypeLoadException(string className, - string assemblyName, - string messageArg, - int resourceId) - : base(null) - { - HResult = HResults.COR_E_TYPELOAD; - ClassName = className; - AssemblyName = assemblyName; - MessageArg = messageArg; - ResourceId = resourceId; - - // Set the _message field eagerly; debuggers look at this field to - // display error info. They don't call the Message property. - SetMessageField(); - } - - protected TypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) - { - ClassName = info.GetString("TypeLoadClassName"); - AssemblyName = info.GetString("TypeLoadAssemblyName"); - MessageArg = info.GetString("TypeLoadMessageArg"); - ResourceId = info.GetInt32("TypeLoadResourceID"); - } - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void GetTypeLoadExceptionMessage(int resourceId, StringHandleOnStack retString); - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue("TypeLoadClassName", ClassName, typeof(string)); - info.AddValue("TypeLoadAssemblyName", AssemblyName, typeof(string)); - info.AddValue("TypeLoadMessageArg", MessageArg, typeof(string)); - info.AddValue("TypeLoadResourceID", ResourceId); - } - - // If ClassName != null, GetMessage will construct on the fly using it - // and ResourceId (mscorrc.dll). This allows customization of the - // class name format depending on the language environment. - private string ClassName; - private string AssemblyName; - private string MessageArg; - internal int ResourceId; - } -} |