Skip to content

Adopt AngleSharp 1.9 and make the library trim and Native AOT compatible - #257

Merged
FlorianRappl merged 1 commit into
AngleSharp:develfrom
michaelthyregod:feature/anglesharp-1.9-aot
Nov 1, 2026
Merged

FlorianRappl merged 1 commit into
AngleSharp:develfrom
michaelthyregod:feature/anglesharp-1.9-aot

Conversation

@michaelthyregod

Copy link
Copy Markdown
Contributor

Types of Changes

Prerequisites

Please make sure you can check the following two boxes:

  • I have read the CONTRIBUTING document
  • My code follows the code style of this project

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue, please reference the issue id)
  • New feature (non-breaking change which adds functionality, make sure to open an associated issue first)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Description

The AngleSharp.Css counterpart of AngleSharp #1398 and AngleSharp.Xml #38: AngleSharp 1.9 as the minimum, and the library marked trim and Native AOT compatible. There is no separate issue.

  • AngleSharp 1.9.0 minimum (csproj default and CI). The trim-safe Css overload below needs AngleSharp's generic ToDictionary<T>, which came with 1.9.0. With 1.9.0, the old call to ToDictionary(Object) is obsolete, so the bump alone would not build (warnings are errors).
  • IsAotCompatible on the net8.0 and net10.0 targets, with the same KnownILLinkPack override as AngleSharp and AngleSharp.Xml. The analyzers flagged one place: Css(Object), which reads the properties of the value's runtime type.
  • New Css<T, TProperties> overload, with the type parameter annotated so the trimmer keeps its public properties. It follows Attr<T, TAttributes> in AngleSharp:
    • the Object overload stays, marked Obsolete and RequiresUnreferencedCode, so code compiled against it keeps working;
    • on a recompile, a call with an anonymous object binds to the generic overload; a dictionary is copied, not reflected over.
  • Internal copies of DynamicallyAccessedMembersAttribute and RequiresUnreferencedCodeAttribute for the targets whose BCL predates them, as in AngleSharp.
  • Tests: Css with an anonymous object, a dictionary and a value declared as Object.
  • AGENTS.md updated. The test and benchmark packages are unchanged.

Checked

  • The package keeps its target frameworks (netstandard2.0, net462, net472, net8.0, net10.0) and its dependencies; only the AngleSharp minimum changes.
  • Apps on net462, net472, net6.0, net7.0, net8.0 and net10.0, and a netstandard2.0 library, build against the packed package without warnings and run correctly.
  • A console app published with PublishAot against the library compiles with no trim or AOT warnings and runs correctly.
  • All tests pass; the solution builds with no warnings.

Suggested CHANGELOG lines

I left CHANGELOG.md out so you can word them; suggestion:

🤖 Generated with Claude Code

- Require AngleSharp 1.9.0 (csproj default and CI), which the trim-safe
  ToDictionary<T> below needs
- Mark the net8.0 and net10.0 targets IsAotCompatible, so the trim and AOT
  analyzers run on every build, with the same KnownILLinkPack override as
  AngleSharp and AngleSharp.Xml
- Add a generic Css<T, TProperties> overload whose type parameter is
  annotated so the trimmer keeps its public properties. The Object overload
  stays, marked Obsolete and RequiresUnreferencedCode, so code compiled
  against it keeps working; on a recompile a call with an anonymous object
  binds to the generic overload, and a dictionary is copied rather than
  reflected over
- Add internal copies of DynamicallyAccessedMembersAttribute and
  RequiresUnreferencedCodeAttribute for the targets whose BCL predates them
- Add tests for Css with an anonymous object, a dictionary and a value
  declared as Object
- Update AGENTS.md

The package keeps its target frameworks and its dependencies apart from the
AngleSharp minimum. Apps on net462, net472, net6.0, net7.0, net8.0 and
net10.0 and a netstandard2.0 library build against the packed package
without warnings and run correctly, and a console app published with
PublishAot compiles with no trim or AOT warnings.
@CLAassistant

CLAassistant commented Nov 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants