runtime: Reflection regression - Type.GetType does not skip leading `.`
Description
Type.GetType
does not find the type when type name starts with .
(dot)…
Reproduction Steps
class MyType
{
static void Main() => Console.WriteLine(Type.GetType(".MyType"));
}
Expected behavior
Type is found
Actual behavior
Type is not found
Regression?
Yes, this used to work on SDK 8.0.100-preview.4.23171.22
Known Workarounds
No response
Configuration
SDK 8.0.100-preview.4.23210.1 macOS-11.6.7 x64
Other information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (17 by maintainers)
Commits related to this issue
- Fix Type.GetType for global type names with leading '.' Ignore leading '.' for global typenames for compatibility with earlier .NET versions. Fixes #84644 — committed to jkotas/runtime by jkotas a year ago
- Fix Type.GetType for global type names with leading '.' Ignore leading '.' for global typenames for compatibility with earlier .NET versions. Fixes #84644 — committed to jkotas/runtime by jkotas a year ago
- Fix Type.GetType for global type names with leading '.' (#84957) Ignore leading '.' for global typenames for compatibility with earlier .NET versions. Fixes #84644 — committed to dotnet/runtime by jkotas a year ago
- Fix Type.GetType for global type names with leading '.' (#84957) Ignore leading '.' for global typenames for compatibility with earlier .NET versions. Fixes #84644 — committed to vitek-karas/runtime by jkotas a year ago
- Fix Type.GetType for global type names with leading '.' (#84957) Ignore leading '.' for global typenames for compatibility with earlier .NET versions. Fixes #84644 — committed to kunalspathak/runtime by jkotas a year ago
@EgorBo Thank you for taking a look!
The problem is in
Type.GetType
API and it affects all platforms (it is not OSX specific). I have updated the description.assembly.GetType(".GlobalNamespaceContextModel")
is the statement in the repro that triggered the issue.The issue is that
Type.GetType
implementation had a quirk that made it ignore leading.
in the type name. The new managed type name parser is missing this quirk.