-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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]: MetadataReader.GetAssemblyName(string assemblyFile) #63960
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata Issue DetailsBackground and motivation. API Proposalnamespace System.Collections.Generic
{
public class MyFancyCollection<T> : IEnumerable<T>
{
public void Fancy(T item);
}
} API Usage// Fancy the value
var c = new MyFancyCollection<int>();
c.Fancy(42);
// Getting the values out
foreach (var v in c)
Console.WriteLine(v); Alternative DesignsNo response Risks.
|
CC: @agocke |
Yest I was OK with the API shape/name because @VSadov moved the existing API implementation from runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs Line 190 in cfd1241
But I believe it is not have to be same as one in AssemblyName , so I am open for better naming suggestions
|
Personally, I think @dotnet/fxdc, any preferences? |
What I can't understand is how this method would be called from corelib, if that's what you want to do. |
It is called from corelib via reflection today: runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs Line 192 in cfd1241
The reason to make the API public in the new location is to make this explicit. Alternative designs paragraph above talks about it. |
[Triage:] we are OK with keeping the name as is, to express that it is same API as the one in |
Background and motivation
As part of #63915 we are moving
AssemblyName.GetAssemblyName(string assemblyFile)
implementation to managed code, so we need a helper entry point inSystem.Reflection.Metadata
.Current implementation relies on VM assembly loader, but intentionally bypasses the internal caches so that the call has no lasting effects on the runtime state.
The implementation also needs to handle assemblies that do not match the current platform, which is an awkward situation for the assembly loader and require special handling.
As it is, every runtime (CoreClr, Mono, CoreRT) needs to implement
AssemblyName.GetAssemblyName
leading to inconsistencies in implementation. Providing a common managed implementation is very desirable.Since this is all about PE/Assembly parsing,
System.Reflection.Metadata
appears to be a logical place for the implementation.While internal helper could be sufficient, it is better if the helper is public. In fact the helper may become the primary/recommended way to fetch an assembly name.
API Proposal
namespace System.Reflection.Metadata { public sealed partial class MetadataReader { // given a path to assembly returns its AssemblyName similarly to AssemblyName.GetAssemblyName // in fact AssemblyName.GetAssemblyName will use this implementation. + public static AssemblyName GetAssemblyName(string assemblyFile) { ... } } }
== Exceptions:
AssemblyName.GetAssemblyName
handles failure cases by throwing a range of exceptions. It may be difficult to match every error case precisely. Inconsistencies in the file format typically lead toBadImageFormatException
.There is less consistency for other issues like file/IO and there are some disagreements between platforms and different OSs.
== Proposal:
Map
InvalidOperationException
coming from MetadataReader toBadImageFormatException
with the same message to minimize compat concerns. Propagate other exceptions as-is.API Usage
Alternative Designs
It would be ok if the helper is internal, but measures will need to be taken that it is not trimmed by the linker and does not disappear in future/alternative implementations of
System.Reflection.Metadata
Risks
Low. This is a new API entry point exposing existing implementation.
The text was updated successfully, but these errors were encountered: