Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeLoadException.TypeName no longer contains the fully qualified name of the type that caused the exception. #111059

Open
drieseng opened this issue Jan 3, 2025 · 0 comments
Labels
area-TypeSystem-coreclr untriaged New issue has not been triaged by the area owner

Comments

@drieseng
Copy link
Contributor

drieseng commented Jan 3, 2025

Description

The TypeName property of TypeLoadException is documented to contain the fully qualified name of the type that caused the exception.

However, this property returns an empty string when the TypeLoadException is thrown by at least the following methods in both .NET 8.0 and .NET 9.0:

  • System.Reflection.Assembly.GetType(string name, bool throwOnError)
  • System.Type.GetType(string name, bool throwOnError)

Reproduction Steps

Compile and run the following code:

using System;
using System.Reflection;

public class Program
{
    private static void Main()
    {
        // Get a reference to the assembly mscorlib.dll, which is always
        // loaded. (System.String is defined in mscorlib.)
        Assembly mscorlib = typeof(string).Assembly;

        try
        {
            Console.WriteLine("Attempting to load a type that does not exist in mscorlib.");
            // The boolean parameter causes an exception to be thrown if the
            // type is not found.
            Type myType = mscorlib.GetType("System.NonExistentType", true);
        }
        catch (TypeLoadException ex)
        {
            // Display the name of the type that was not found, and the
            // exception message.
            Console.WriteLine("TypeLoadException was caught. Type = '{0}'.",
                ex.TypeName);
            Console.WriteLine("Error Message = '{0}'", ex.Message);
        }
    }
}

Important:
This code fragment is taken from the doc page of TypeLoadException.TypeName:
https://learn.microsoft.com/en-us/dotnet/api/system.typeloadexception.typename?view=net-9.0

Expected behavior

The following text is written to the console / stdout:

Attempting to load a type that does not exist in mscorlib.
TypeLoadException was caught. Type = ''.
...

Actual behavior

The following text is written to the console / stdout:

Attempting to load a type that does not exist in mscorlib.
TypeLoadException was caught. Type = 'System.NonExistentType'.
...

This is the output that you get on .NET Framework 4.8 and this is also the expected output that is documented on the doc page of TypeLoadException.TypeName:
https://learn.microsoft.com/en-us/dotnet/api/system.typeloadexception.typename?view=net-9.0

Regression?

This is a regression from the .NET Framework 4.8 implementation, and the .NET implementation also does not correspond with the doc page of TypeLoadException.TypeName:
https://learn.microsoft.com/en-us/dotnet/api/system.typeloadexception.typename?view=net-9.0

Known Workarounds

None

Configuration

  • .NET 8.0 or .NET 9.0, I haven't checked earlier versions.
  • Windows 11 version 23H2
  • X64

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 3, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 3, 2025
@MihaZupan MihaZupan added area-TypeSystem-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TypeSystem-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants