Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<ResourceManager> s_stringResourceManager =
new Lazy<ResourceManager>(() => new ResourceManager("Internal.TypeSystem.Strings", typeof(TypeSystemException).GetTypeInfo().Assembly));

public static string GetFormatString(ExceptionStringID id)
{
return s_stringResourceManager.Value.GetString(id.ToString(), CultureInfo.InvariantCulture);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Internal.TypeSystem
/// <summary>
/// Base type for all type system exceptions.
/// </summary>
public abstract class TypeSystemException : Exception
public abstract partial class TypeSystemException : Exception
{
private string[] _arguments;

Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
14 changes: 8 additions & 6 deletions src/coreclr/src/tools/ILVerification/ILVerification.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
<Compile Include="$(MSBuildThisFileDirectory)Verifier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)VerifierError.cs" />
</ItemGroup>
<PropertyGroup>
<ToolsCommonPath>$(MSBuildThisFileDirectory)..\Common\</ToolsCommonPath>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Strings.resx">
<LogicalName>ILVerification.Strings.resources</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="..\Common\TypeSystem\Common\Properties\Resources.resx">
<GenerateSource>true</GenerateSource>
<ClassName>Internal.TypeSystem.SR</ClassName>
<EmbeddedResource Include="$(ToolsCommonPath)TypeSystem\Common\Properties\Resources.resx">
<LogicalName>Internal.TypeSystem.Strings.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<ToolsCommonPath>$(MSBuildThisFileDirectory)..\Common\</ToolsCommonPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(ToolsCommonPath)TypeSystem\CodeGen\MethodDesc.CodeGen.cs">
<Link>TypeSystem\CodeGen\MethodDesc.CodeGen.cs</Link>
Expand Down Expand Up @@ -53,6 +52,9 @@
<Compile Include="$(ToolsCommonPath)TypeSystem\Common\TypeSystemException.cs">
<Link>TypeSystem\Common\TypeSystemException.cs</Link>
</Compile>
<Compile Include="$(ToolsCommonPath)TypeSystem\Common\TypeSystemException.Resources.cs">
<Link>TypeSystem\Common\TypeSystemException.Resources.cs</Link>
</Compile>
<Compile Include="$(ToolsCommonPath)TypeSystem\Common\Utilities\CustomAttributeTypeNameParser.cs">
<Link>Utilities\CustomAttributeTypeNameParser.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
<Compile Include="StaticFieldLayoutTests.cs" />
<Compile Include="TestTypeSystemContext.cs" />
<Compile Include="WellKnownTypeTests.cs" />
<Compile Include="ExceptionStringTests.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

<ItemGroup Label="Embedded Resources">
<EmbeddedResource Include="..\..\Common\TypeSystem\Common\Properties\Resources.resx">
<GenerateSource>true</GenerateSource>
<ClassName>Internal.TypeSystem.SR</ClassName>
<LogicalName>Internal.TypeSystem.Strings.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>

Expand Down Expand Up @@ -153,6 +152,9 @@
<Compile Include="..\..\Common\TypeSystem\Common\TypeSystemException.cs">
<Link>TypeSystem\Common\TypeSystemException.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\TypeSystemException.Resources.cs">
<Link>TypeSystem\Common\TypeSystemException.Resources.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\ThrowHelper.cs">
<Link>TypeSystem\Common\ThrowHelper.cs</Link>
</Compile>
Expand Down
31 changes: 31 additions & 0 deletions src/tests/ilverify/ILVerification.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>$(BaseOutputPathWithConfig)ilverify\</OutputPath>
<CLRTestPriority>1</CLRTestPriority>
<!-- The test uses xunit directly and it fails to find the test assembly for some reason -->
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Include="ILMethodTester.cs" />
<Compile Include="ILTypeVerificationTester.cs" />
<Compile Include="TestDataLoader.cs" />
<Compile Include="..\Common\XunitBase.cs" />
</ItemGroup>

<Import Project="..\..\coreclr\src\tools\ILVerification\ILVerification.projitems" />

<ItemGroup>
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="ILTests\*.ilproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
</ProjectReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/tests/ilverify/TestDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestDataLoader
/// <summary>
/// The folder with the test binaries
/// </summary>
private const string TestAssemblyPath = @"Tests\";
private const string TestAssemblyPath = @"Tests";

private const string SpecialTestPrefix = "special.";

Expand Down Expand Up @@ -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;
Expand Down