Skip to content

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

Closed

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.

Activity

  1. ghost added
    untriaged
    on May 31, 2022
  2. added this to the 7.0.0 milestone on May 31, 2022
  3. ghost removed
    untriaged
    on May 31, 2022
  4. agocke commented on Jun 16, 2022

    @agocke
    Member

    @hez2010 Sorry, not sure I understand. These look like the same type, but one is in metadata naming format and the other is in C# format. Is there any other different?

  5. hez2010 commented on Jun 17, 2022

    @hez2010
    ContributorAuthor

    The metadata qualified name is needed in rd.xml. If the exception message contains the metadata type name, developers can write the type name in rd.xml without looking up the source code.

  6. added a commit that references this issue on Aug 9, 2022
    d98a0e9
  7. ghost added
    in-pr
    on Aug 9, 2022
  8. ghost removed
    in-pr
    on Aug 11, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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