You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;usingSystem.Reflection;publicclassProgram{privatestaticvoidMain(){// Get a reference to the assembly mscorlib.dll, which is always// loaded. (System.String is defined in mscorlib.)Assemblymscorlib=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.TypemyType=mscorlib.GetType("System.NonExistentType",true);}catch(TypeLoadExceptionex){// 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);}}}
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:
Reproduction Steps
Compile and run the following code:
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:
Actual behavior
The following text is written to the console / stdout:
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
Other information
No response
The text was updated successfully, but these errors were encountered: