-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add public APIs for persisted AssemblyBulder #97177
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue Details
namespace System.Reflection.Emit;
public partial class AssemblyBuilder
{
// New API - note that it does not have RequiresDynamicCode annotation
public static AssemblyBuilder DefinePersistedAssembly(AssemblyName name, Assembly coreAssembly, IEnumerable<CustomAttributeBuilder>? assemblyAttributes = null);
public void Save(Stream stream);
public void Save(string assemblyFileName);
protected abstract void SaveCore(Stream stream);
}
|
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Show resolved
Hide resolved
/// When implemented in derived type serializer the assembly to stream. | ||
/// </summary> | ||
/// <param name="stream">The stream to which the assembly serialized.</param> | ||
protected abstract void SaveCore(Stream stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it not possible for someone externally to derive from AssemblyBuilder in .NET 8 and earlier? Adding a new abstract method will break anyone who did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made the AssemblyBuilder
abstract in .NET 8, before it was sealed. So only .NET 8 can be considered, and I think it's unlikely somebody would have derived from AssemblyBuilder
and build their own implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it was possible to derive from AssemblyBuilder in .NET 8, then this is a binary breaking change. I think we need to make it virtual with the base implementation throwing.
cc: @terrajobst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; some misc comments. Thanks for this important feature!
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids --> | |||
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |||
</Suppressions> | |||
</Suppressions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: revert this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is reverted, could not revert the line ending
...aries/System.Reflection.Emit/tests/PersistableAssemblyBuilder/AssemblySaveAssemblyBuilder.cs
Show resolved
Hide resolved
Failures unrelated and known |
* Add public APIs for persisted AssemblyBuilder * Update tests to use public API, refactor tests so that the temp files deleted * Make AB.SaveCore(Stream) virtual and add meaningful message for excepiton thrown Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Remove unneeded message * Update newer tests to use new public APIs --------- Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Contributes to #92975