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

Parsing assembly qualified type name fails #84118

Closed
rolfbjarne opened this issue Mar 30, 2023 · 4 comments · Fixed by #84141
Closed

Parsing assembly qualified type name fails #84118

rolfbjarne opened this issue Mar 30, 2023 · 4 comments · Fixed by #84141

Comments

@rolfbjarne
Copy link
Member

Description

Parsing the type name "System.Int32, , System.Private.CoreLib.dll" fails in the latest .NET 8 builds.

Reproduction Steps

Test code:

var t = Type.GetType ("System.Int32, , System.Private.CoreLib.dll");
Console.WriteLine (t);

Expected behavior

This should be printed:

System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Actual behavior

An exception:

Unhandled exception. System.IO.FileLoadException: The given assembly name was invalid.
File name: ', System.Private.CoreLib.dll'
   at System.Reflection.AssemblyNameParser.ThrowInvalidAssemblyName()
   at System.Reflection.AssemblyNameParser.Parse()
   at System.Reflection.AssemblyNameParser.Parse(String name)
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at System.Reflection.TypeNameParser.ResolveAssembly(String assemblyName)
   at System.Reflection.TypeNameParser.GetType(String typeName, ReadOnlySpan`1 nestedTypeNames, String assemblyNameIfAny)
   at System.Reflection.TypeNameParser.NamespaceTypeName.ResolveType(TypeNameParser& parser, String containingAssemblyIfAny)
   at System.Reflection.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Assembly requestingAssembly, Boolean throwOnError, Boolean ignoreCase, Boolean extensibleParser)
   at System.Type.GetType(String typeName)

Regression?

Yes, the code works fine in .NET 7.

Known Workarounds

No response

Configuration

/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/dotnet --info
.NET SDK:
 Version:   8.0.100-preview.4.23178.2
 Commit:    69e28735b9

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.3
 OS Platform: Darwin
 RID:         osx.13-x64
 Base Path:   /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk/8.0.100-preview.4.23178.2/

.NET workloads installed:
 [macos]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    13.1.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.macos/WorkloadManifest.json
   Install Type:        FileBased
 [ios]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.2.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.ios/WorkloadManifest.json
   Install Type:        FileBased
 [maccatalyst]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.2.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.maccatalyst/WorkloadManifest.json
   Install Type:        FileBased
 [tvos]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.1.9315-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.tvos/WorkloadManifest.json
   Install Type:        FileBased

Host:
  Version:      8.0.0-preview.4.23176.4
  Architecture: x64
  Commit:       8d5f520838

.NET SDKs installed:
  8.0.100-preview.4.23178.2 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-preview.4.23176.6 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-preview.4.23176.4 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

It happened somewhere in this range: edb161a...8d5f520

I'm guessing this is the culprit: #83484

CC @jkotas

@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 Mar 30, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 30, 2023
@ghost
Copy link

ghost commented Mar 30, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Parsing the type name "System.Int32, , System.Private.CoreLib.dll" fails in the latest .NET 8 builds.

Reproduction Steps

Test code:

var t = Type.GetType ("System.Int32, , System.Private.CoreLib.dll");
Console.WriteLine (t);

Expected behavior

This should be printed:

System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Actual behavior

An exception:

Unhandled exception. System.IO.FileLoadException: The given assembly name was invalid.
File name: ', System.Private.CoreLib.dll'
   at System.Reflection.AssemblyNameParser.ThrowInvalidAssemblyName()
   at System.Reflection.AssemblyNameParser.Parse()
   at System.Reflection.AssemblyNameParser.Parse(String name)
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at System.Reflection.TypeNameParser.ResolveAssembly(String assemblyName)
   at System.Reflection.TypeNameParser.GetType(String typeName, ReadOnlySpan`1 nestedTypeNames, String assemblyNameIfAny)
   at System.Reflection.TypeNameParser.NamespaceTypeName.ResolveType(TypeNameParser& parser, String containingAssemblyIfAny)
   at System.Reflection.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Assembly requestingAssembly, Boolean throwOnError, Boolean ignoreCase, Boolean extensibleParser)
   at System.Type.GetType(String typeName)

Regression?

Yes, the code works fine in .NET 7.

Known Workarounds

No response

Configuration

/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/dotnet --info
.NET SDK:
 Version:   8.0.100-preview.4.23178.2
 Commit:    69e28735b9

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.3
 OS Platform: Darwin
 RID:         osx.13-x64
 Base Path:   /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk/8.0.100-preview.4.23178.2/

.NET workloads installed:
 [macos]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    13.1.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.macos/WorkloadManifest.json
   Install Type:        FileBased
 [ios]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.2.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.ios/WorkloadManifest.json
   Install Type:        FileBased
 [maccatalyst]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.2.8527-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.maccatalyst/WorkloadManifest.json
   Install Type:        FileBased
 [tvos]
   Installation Source: SDK 8.0.100-preview.4
   Manifest Version:    16.1.9315-ci.darc-net8-0-78d17446-9936-45f9-8740-af082689e6f6/8.0.100-preview.2
   Manifest Path:       /Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk-manifests/8.0.100-preview.2/microsoft.net.sdk.tvos/WorkloadManifest.json
   Install Type:        FileBased

Host:
  Version:      8.0.0-preview.4.23176.4
  Architecture: x64
  Commit:       8d5f520838

.NET SDKs installed:
  8.0.100-preview.4.23178.2 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-preview.4.23176.6 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-preview.4.23176.4 [/Users/rolf/work/maccore/net8.0/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.4.23178.2/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

It happened somewhere in this range: edb161a...8d5f520

I'm guessing this is the culprit: #83484

CC @jkotas

Author: rolfbjarne
Assignees: -
Labels:

area-System.Reflection, untriaged, needs-area-label

Milestone: -

@marek-safar marek-safar removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 30, 2023
@stephentoub
Copy link
Member

It happened somewhere in this range: edb161a...8d5f520

We're sure? Based purely on history I would have guessed I might have broken it a few months ago in https://github.com/dotnet/runtime/pull/79048/files#diff-6552989a804d7e6b6e1f065a88d8c17221ea6c6ad561d66348d2f85668f6261f.

@rolfbjarne
Copy link
Member Author

It happened somewhere in this range: edb161a...8d5f520

We're sure? Based purely on history I would have guessed I might have broken it a few months ago in #79048 (files).

It started breaking in this maestro bump: xamarin/xamarin-macios#17888

@jkotas
Copy link
Member

jkotas commented Mar 30, 2023

I'm guessing this is the culprit: #83484

Yes, the behavior regressed with this change. I am working on a fix.

The expected behavior is not correct. System.Int32, , System.Private.CoreLib.dll is invalid type name - the extra comma makes it invalid. Type.GetType with throwOnError:false should return null for it. It is what it did in .NET 7.

jkotas added a commit to jkotas/runtime that referenced this issue Mar 30, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 30, 2023
@buyaa-n buyaa-n added this to the 8.0.0 milestone Mar 30, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 30, 2023
jkotas added a commit that referenced this issue Mar 31, 2023
…assembly name (#84141)

* Fix type parsing error returned for type names with invalid start of assembly name

Fixes #84118

* Mono error handling is different
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 31, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Apr 10, 2023
… that showed up in code.

There's a 'link all' test that's verifying that the IntroducedAttribute is
linked away. It does so by verifying that the linked app doesn't have a
'IntroducedAttribute' type - but the test was constructing the fully qualified
type name to look for incorrectly:

    ObjCRuntime.IntroducedAttribute, , Microsoft.iOS

Note the double comma: that meant we wouldn't find the type, even if it wasn't linked away.

The fix is easy (use a single comma), with one caveat (don't use a constant
string, because the linker sees the reference to
"ObjCRuntime.IntroducedAttribute" and _helpfully_ preserves it, exactly what
we don't want), but it revealed that the tested behavior regressed: a fully
linked app wouldn't link away the IntroducedAttribute.

So a fix is also needed: properly remove TVAttribute, WatchAttribute and
MacCatalystAttribute, which are subclasses of IntroducedAttribute (and what
would make the linker keep IntroducedAttribute).

Interestingly this showed up because of a bug in the runtime, where parsing
the invalid assembly name would now throw an exception
(dotnet/runtime#84118).
rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Apr 11, 2023
… that showed up in code. (#18016)

There's a 'link all' test that's verifying that the IntroducedAttribute is
linked away. It does so by verifying that the linked app doesn't have a
'IntroducedAttribute' type - but the test was constructing the fully qualified
type name to look for incorrectly:

    ObjCRuntime.IntroducedAttribute, , Microsoft.iOS

Note the double comma: that meant we wouldn't find the type, even if it wasn't linked away.

The fix is easy (use a single comma), with one caveat (don't use a constant
string, because the linker sees the reference to
"ObjCRuntime.IntroducedAttribute" and _helpfully_ preserves it, exactly what
we don't want), but it revealed that the tested behavior regressed: a fully
linked app wouldn't link away the IntroducedAttribute.

So a fix is also needed: properly remove TVAttribute, WatchAttribute and
MacCatalystAttribute, which are subclasses of IntroducedAttribute (and what
would make the linker keep IntroducedAttribute).

Interestingly this showed up because of a bug in the runtime, where parsing
the invalid assembly name would now throw an exception
(dotnet/runtime#84118).
@ghost ghost locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants