-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: New AssemblyName-like type for TypeName parsing #100867
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata |
How about naming it |
Should this have a public constructor that allows you to set all constituent parts? |
Should this have a FromAssemblyName method too? |
If you're looking for code that could use this, I'd want to switch the managed type system to this AssemblyName: runtime/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs Lines 11 to 18 in 674ba3f
We're using AssemblyName right now and it's probably the only reason why we cannot turn on culture invariant mode on tools that use the managed type system. AssemblyName is unusable when culture invariant mode is enabled due to the cultureinfo. |
Great idea, I am going to use it as the name in the proposal.
Not in my use case, but it makes total sense to have it.
Not in my use case and a very similar internal type from NativeAOT RuntimeAssemblyName also did not need that, so for now I would say no.
Great! |
I've tried to implement the API today and found out following things:
Please let me know if you believe that my observations are wrong. |
This type should not be doing any validation of the PublicKey or PublicKeyToken; or try to compute PublicKeyToken from PublicKey. It should treat the PublicKeyToken/PublicKey as an opaque blob. (BTW: We have been going in this direction for the assembly loader in modern .NET. Strong names and strong name mismatches are ignored by the assembly loader, and the publickey/publickeytoken are just treated as opaque blobs that are passed around for backward compatibility.) We may want to have just a single property The existing behavior of AssemblyName.FullName that converts PublicKey to PublicKeyToken is questionable. It is perfectly fine to have full assembly name with public key. I do not think we want copy this behavior in this type. The full name should match what you have constructed the AssemblyNameInfo with, without any conversions. |
How would be go about implementing |
I would expect that
|
namespace System.Reflection.Metadata;
public sealed class AssemblyNameInfo
{
public AssemblyNameInfo(string name, Version? version = null, string? cultureName = null, AssemblyNameFlags flags = AssemblyNameFlags.None,
Collections.Immutable.ImmutableArray<byte> publicKeyOrToken = default);
public string Name { get; }
public string FullName { get; }
public Version? Version { get; }
public string? CultureName { get; }
public AssemblyNameFlags Flags { get; }
public ImmutableArray<byte> PublicKeyOrToken { get; }
public AssemblyName ToAssemblyName();
public static AssemblyNameInfo Parse(ReadOnlySpan<char> assemblyName);
public static bool TryParse(ReadOnlySpan<char> assemblyName, [NotNullWhenAttribute(true)] out AssemblyNameInfo? result);
} -public sealed partial class TypeName : IEquatable<TypeName>
+public sealed partial class TypeName
{
- public string AssemblySimpleName { get; }
- public System.Reflection.AssemblyName? GetAssemblyName();
+ public AssemblyNameInfo? AssemblyName { get; }
} |
I really think |
Looking at |
I really think the types should implement EDIT: I do admit that it doesn't exactly match the interface because it also takes an |
Background and Motivation
While working on the implementation of
TypeName
API (#97566), it turned out that it's impossible to setAssemblyName.CultureName
without allocating aCultrueInfo
instance (using public NS2.0 compatibile APIs).runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs
Line 83 in 0764864
The type name parser needs to support parsing from untrusted input and such non-predefined culture name may be used as a vector of attack, so the existing
AssemblyName
is not suitable for our needs.Since
AssemblyName
suffers from some other design issues (mutability, a LOT of obsolete properties), I would like to introduce a new, immutable, lightweight version ofAssemblyName
type.Proposed API
It's a concept and I need the help of API review board to choose the right name. Some of my ideas:
ReadOnlyAssemblyName
,AssemblyId
,LibraryName
.The approved
TypeName
API needs following changes:Usage Examples
Building high-level, opinionated parser on top of the low-level API:
Alternative Designs
The proposed design has one property
PublickKeyOrToken
that can express the public key or its token. It's a design choice inherited fromAssemblyName
that usesAssemblyNameFlags.PublicKey
flag to express what given byte array is.We could have two dedicated properties and ctor arguments to express that:
PublicKey
andPublicKeyToken
.Risks
Providing low quality design may require introducing another
AssemblyName
-like type in the future.The text was updated successfully, but these errors were encountered: