diff --git a/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.Resources.cs b/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.Resources.cs new file mode 100644 index 00000000000000..bf5a3b97b292f4 --- /dev/null +++ b/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.Resources.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Resources; +using System.Reflection; + +// This partial file is designed to allow the runtime variant of the type system to not +// need to support accessing these strings via the ResourceManager +namespace Internal.TypeSystem +{ + partial class TypeSystemException : Exception + { + private static Lazy s_stringResourceManager = + new Lazy(() => new ResourceManager("Internal.TypeSystem.Strings", typeof(TypeSystemException).GetTypeInfo().Assembly)); + + public static string GetFormatString(ExceptionStringID id) + { + return s_stringResourceManager.Value.GetString(id.ToString(), CultureInfo.InvariantCulture); + } + } +} diff --git a/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.cs b/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.cs index c9a71236c4daf0..931136950f1afc 100644 --- a/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.cs +++ b/src/coreclr/src/tools/Common/TypeSystem/Common/TypeSystemException.cs @@ -9,7 +9,7 @@ namespace Internal.TypeSystem /// /// Base type for all type system exceptions. /// - public abstract class TypeSystemException : Exception + public abstract partial class TypeSystemException : Exception { private string[] _arguments; @@ -43,53 +43,19 @@ internal TypeSystemException(ExceptionStringID id, params string[] args) _arguments = args; } - private static string GetFormatString(ExceptionStringID id) - { - switch (id) - { - case ExceptionStringID.ClassLoadGeneral: return SR.ClassLoadGeneral; - case ExceptionStringID.ClassLoadBadFormat: return SR.ClassLoadBadFormat; - case ExceptionStringID.ClassLoadExplicitGeneric: return SR.ClassLoadExplicitGeneric; - case ExceptionStringID.ClassLoadExplicitLayout: return SR.ClassLoadExplicitLayout; - case ExceptionStringID.ClassLoadValueClassTooLarge: return SR.ClassLoadValueClassTooLarge; - case ExceptionStringID.ClassLoadRankTooLarge: return SR.ClassLoadRankTooLarge; - case ExceptionStringID.MissingMethod: return SR.MissingMethod; - case ExceptionStringID.MissingField: return SR.MissingField; - case ExceptionStringID.InvalidProgramDefault: return SR.InvalidProgramDefault; - case ExceptionStringID.InvalidProgramSpecific: return SR.InvalidProgramSpecific; - case ExceptionStringID.InvalidProgramVararg: return SR.InvalidProgramVararg; - case ExceptionStringID.InvalidProgramCallVirtFinalize: return SR.InvalidProgramCallVirtFinalize; - case ExceptionStringID.InvalidProgramUnmanagedCallersOnly: return SR.InvalidProgramUnmanagedCallersOnly; - case ExceptionStringID.InvalidProgramCallAbstractMethod: return SR.InvalidProgramCallAbstractMethod; - case ExceptionStringID.InvalidProgramCallVirtStatic: return SR.InvalidProgramCallVirtStatic; - case ExceptionStringID.InvalidProgramNonStaticMethod: return SR.InvalidProgramNonStaticMethod; - case ExceptionStringID.InvalidProgramGenericMethod: return SR.InvalidProgramGenericMethod; - case ExceptionStringID.InvalidProgramNonBlittableTypes: return SR.InvalidProgramNonBlittableTypes; - case ExceptionStringID.BadImageFormatGeneric: return SR.BadImageFormatGeneric; - case ExceptionStringID.FileLoadErrorGeneric: return SR.FileLoadErrorGeneric; - } -#if !DEBUG - throw new Exception($"Unknown Exception string id {id}"); -#else - return null; -#endif - } - private static string GetExceptionString(ExceptionStringID id, string[] args) { string formatString = GetFormatString(id); -#if !DEBUG try { -#endif - return String.Format(formatString, (object[])args); -#if !DEBUG - } - catch - { - return "[TEMPORARY EXCEPTION MESSAGE] " + id.ToString() + ": " + String.Join(", ", args); + if (formatString != null) + { + return String.Format(formatString, (object[])args); + } } -#endif + catch {} + + return "[TEMPORARY EXCEPTION MESSAGE] " + id.ToString() + ": " + String.Join(", ", args); } /// diff --git a/src/coreclr/src/tools/ILVerification/ILVerification.projitems b/src/coreclr/src/tools/ILVerification/ILVerification.projitems index bc5bda42bc03cf..42f60611ee1813 100644 --- a/src/coreclr/src/tools/ILVerification/ILVerification.projitems +++ b/src/coreclr/src/tools/ILVerification/ILVerification.projitems @@ -13,18 +13,17 @@ + + $(MSBuildThisFileDirectory)..\Common\ + ILVerification.Strings.resources - - true - Internal.TypeSystem.SR + + Internal.TypeSystem.Strings.resources - - $(MSBuildThisFileDirectory)..\Common\ - TypeSystem\CodeGen\MethodDesc.CodeGen.cs @@ -53,6 +52,9 @@ TypeSystem\Common\TypeSystemException.cs + + TypeSystem\Common\TypeSystemException.Resources.cs + Utilities\CustomAttributeTypeNameParser.cs diff --git a/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ExceptionStringTests.cs b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ExceptionStringTests.cs new file mode 100644 index 00000000000000..d40bdf774126d8 --- /dev/null +++ b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ExceptionStringTests.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using Internal.TypeSystem; + +using Xunit; + +namespace TypeSystemTests +{ + public class ExceptionStringTests + { + public ExceptionStringTests() + { + } + + [Fact] + public void TestAllExceptionIdsHaveMessages() + { + foreach(var exceptionId in (ExceptionStringID[])Enum.GetValues(typeof(ExceptionStringID))) + { + Assert.NotNull(TypeSystemException.GetFormatString(exceptionId)); + } + } + } +} \ No newline at end of file diff --git a/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj index 38e1dda8abaaf4..c65d2b0b54dd55 100644 --- a/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj +++ b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj @@ -56,5 +56,6 @@ + diff --git a/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun/ILCompiler.TypeSystem.ReadyToRun.csproj b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun/ILCompiler.TypeSystem.ReadyToRun.csproj index 733bd833c140a7..cea2c969468d42 100644 --- a/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun/ILCompiler.TypeSystem.ReadyToRun.csproj +++ b/src/coreclr/src/tools/aot/ILCompiler.TypeSystem.ReadyToRun/ILCompiler.TypeSystem.ReadyToRun.csproj @@ -19,8 +19,7 @@ - true - Internal.TypeSystem.SR + Internal.TypeSystem.Strings.resources @@ -153,6 +152,9 @@ TypeSystem\Common\TypeSystemException.cs + + TypeSystem\Common\TypeSystemException.Resources.cs + TypeSystem\Common\ThrowHelper.cs diff --git a/src/tests/ilverify/ILVerification.Tests.csproj b/src/tests/ilverify/ILVerification.Tests.csproj new file mode 100644 index 00000000000000..5eaea1b89ea441 --- /dev/null +++ b/src/tests/ilverify/ILVerification.Tests.csproj @@ -0,0 +1,31 @@ + + + Exe + $(BaseOutputPathWithConfig)ilverify\ + 1 + + true + true + + + + + + + + + + + + + + + + + + + false + Content + + + diff --git a/src/tests/ilverify/TestDataLoader.cs b/src/tests/ilverify/TestDataLoader.cs index 7678981dd4a9a9..cd8709d9626ab6 100644 --- a/src/tests/ilverify/TestDataLoader.cs +++ b/src/tests/ilverify/TestDataLoader.cs @@ -27,7 +27,7 @@ class TestDataLoader /// /// The folder with the test binaries /// - private const string TestAssemblyPath = @"Tests\"; + private const string TestAssemblyPath = @"Tests"; private const string SpecialTestPrefix = "special."; @@ -236,7 +236,7 @@ public static EcmaModule GetModuleForTestAssembly(string assemblyName) foreach (var fileName in GetAllTestDlls()) { - simpleNameToPathMap.Add(Path.GetFileNameWithoutExtension(fileName), TestAssemblyPath + fileName); + simpleNameToPathMap.Add(Path.GetFileNameWithoutExtension(fileName), Path.Combine(TestAssemblyPath, fileName)); } Assembly coreAssembly = typeof(object).GetTypeInfo().Assembly;