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

Add public APIs for persisted AssemblyBulder #97177

Merged
merged 10 commits into from
Jan 21, 2024
Merged

Conversation

buyaa-n
Copy link
Member

@buyaa-n buyaa-n commented Jan 18, 2024

  • Add public APIs for persisted AssemblyBulder, approve API shape:
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);
}
  • Use the public APIs for testing
  • Refactor tests to make sure temp files disposed after test

Contributes to #92975

Copy link

Note regarding the new-api-needs-documentation label:

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.

@ghost ghost assigned buyaa-n Jan 18, 2024
@ghost
Copy link

ghost commented Jan 18, 2024

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

Issue Details
  • Add public APIs for persisted AssemblyBulder, approve API shape:
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);
}
  • Use the public APIs for testing
  • Refactor tests to make sure temp files disposed after test
Author: buyaa-n
Assignees: -
Labels:

area-System.Reflection.Emit, new-api-needs-documentation

Milestone: -

/// 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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copy link
Member

@steveharter steveharter left a 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!

@@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert this file

Copy link
Member Author

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

@buyaa-n
Copy link
Member Author

buyaa-n commented Jan 21, 2024

Failures unrelated and known

@buyaa-n buyaa-n merged commit bd84a96 into dotnet:main Jan 21, 2024
172 of 178 checks passed
@buyaa-n buyaa-n deleted the ab_save_public branch January 21, 2024 02:23
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
* 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>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants