Skip to content

Drop net8.0 and modernize DllImportResolver invocation-list enumeration#719

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-modernize-invocationlist-enumeration
Jul 13, 2026
Merged

Drop net8.0 and modernize DllImportResolver invocation-list enumeration#719
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-modernize-invocationlist-enumeration

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Drops the out-of-support net8.0 target framework and modernizes the DllImportResolver invocation-list iteration to be allocation-free and AOT/trim-friendly.


Drop net8.0 target framework

net8.0 is out of support, so it is dropped from the three remaining multi-targeting projects (ClangSharp, ClangSharp.Interop, and ClangSharp.UnitTests), leaving net10.0 as the sole target. The generator, CLI, and golden-test projects were already net10.0-only.

The now-dead #if NET8_0 branches in TranslationUnit (object vs System.Threading.Lock) and FieldDecl (string vs char StartsWith/EndsWith overloads) are collapsed to their net9.0+ forms, and the net8.0 reference in the copilot-instructions doc is updated.


Use Delegate.EnumerateInvocationList to enumerate DllImportResolver

TryResolveLibrary previously iterated the multicast delegate's invocation list via System.Linq's GetInvocationList().Cast<DllImportResolver>(), which allocates a Delegate[] plus a LINQ enumerator and pulls in a LINQ dependency that is an AOT/trim smell. With net8.0 dropped, net9.0+ is guaranteed, so this now uses Delegate.EnumerateInvocationList(resolveLibrary), which returns an allocation-free struct enumerator.

Behavior is unchanged: same resolver order, first resolver returning a non-zero IntPtr wins and returns immediately, same fall-through when none resolve, and the existing resolveLibrary is not null guard is preserved. This was the only System.Linq use in the file, so the now-unused using System.Linq; is removed.

-            var resolvers = resolveLibrary.GetInvocationList().Cast<DllImportResolver>();
-
-            foreach (DllImportResolver resolver in resolvers)
+            foreach (DllImportResolver resolver in Delegate.EnumerateInvocationList(resolveLibrary))

Full solution builds with 0 warnings / 0 errors (net10.0 only) and all 3708 generator unit tests pass.

Note

This PR body was drafted by Copilot on my behalf.

tannergooding and others added 2 commits July 12, 2026 20:07
net8.0 is out of support, so drop it from the multi-targeting projects (ClangSharp, ClangSharp.Interop, and ClangSharp.UnitTests), leaving net10.0 as the sole target. The generator, CLI, and golden-test projects were already net10.0-only.

Collapse the now-dead '#if NET8_0' branches in TranslationUnit and FieldDecl to their net9.0+ forms (System.Threading.Lock and the char StartsWith/EndsWith overloads) and update the net8.0 reference in the copilot-instructions doc.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
TryResolveLibrary iterated the multicast delegate's invocation list via System.Linq's GetInvocationList().Cast<DllImportResolver>(), which allocates a Delegate[] plus a LINQ enumerator and pulls in a LINQ dependency that is an AOT/trim smell.

With net8.0 dropped, net9.0+ is guaranteed, so use Delegate.EnumerateInvocationList(resolveLibrary), which returns an allocation-free struct enumerator and is AOT/trim-friendly. Behavior is unchanged: same resolver order, first resolver returning a non-zero IntPtr wins and returns immediately, same fall-through when none resolve, and the existing 'resolveLibrary is not null' guard is preserved. This was the only System.Linq use in the file, so the now-unused 'using System.Linq;' is removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 5e12830 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-modernize-invocationlist-enumeration branch July 13, 2026 03:18
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.

1 participant