Skip to content

Print the qualified name for missing metadata type in exception message #69998

@hez2010

Description

@hez2010

Description

Repro:

using System;
using System.Reflection;
namespace Test;

class Program
{
    static void Main()
    {
        Activator.CreateInstance(Type.GetType("Test.Foo+Bar`1").MakeGenericType(typeof(int)));
    }
}

class Foo
{
    class Bar<T> { public Bar() { Console.WriteLine("ok"); } }
}

csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup>
    <IlcOptimizationPreference>Speed</IlcOptimizationPreference>
    <IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
    <TrimMode>Link</TrimMode>
    <TrimmerDefaultAction>link</TrimmerDefaultAction>
    <IlcTrimMetadata>true</IlcTrimMetadata>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
  </ItemGroup>

</Project>

Reproduction Steps

  1. Build with dotnet publish -c Release -r win-x64
  2. Run bin\Release\net7.0\win-x64\publish\Test.exe

Expected behavior

The exception message should be:

Unhandled Exception: System.Reflection.MissingMetadataException: 'Test.Foo+Bar`1[System.Int32]' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859

Actual behavior

Unhandled Exception: System.Reflection.MissingMetadataException: 'Test.Foo.Bar<System.Int32>' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

This would help developers to identify the missing types easier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions