Drop net8.0 and modernize DllImportResolver invocation-list enumeration#719
Merged
tannergooding merged 2 commits intoJul 13, 2026
Conversation
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
deleted the
tannergooding-modernize-invocationlist-enumeration
branch
July 13, 2026 03:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Drops the out-of-support
net8.0target framework and modernizes theDllImportResolverinvocation-list iteration to be allocation-free and AOT/trim-friendly.Drop net8.0 target framework
net8.0is out of support, so it is dropped from the three remaining multi-targeting projects (ClangSharp,ClangSharp.Interop, andClangSharp.UnitTests), leavingnet10.0as the sole target. The generator, CLI, and golden-test projects were alreadynet10.0-only.The now-dead
#if NET8_0branches inTranslationUnit(objectvsSystem.Threading.Lock) andFieldDecl(string vscharStartsWith/EndsWithoverloads) are collapsed to theirnet9.0+ forms, and thenet8.0reference in the copilot-instructions doc is updated.Use
Delegate.EnumerateInvocationListto enumerateDllImportResolverTryResolveLibrarypreviously iterated the multicast delegate's invocation list viaSystem.Linq'sGetInvocationList().Cast<DllImportResolver>(), which allocates aDelegate[]plus a LINQ enumerator and pulls in a LINQ dependency that is an AOT/trim smell. Withnet8.0dropped,net9.0+ is guaranteed, so this now usesDelegate.EnumerateInvocationList(resolveLibrary), which returns an allocation-free struct enumerator.Behavior is unchanged: same resolver order, first resolver returning a non-zero
IntPtrwins and returns immediately, same fall-through when none resolve, and the existingresolveLibrary is not nullguard is preserved. This was the onlySystem.Linquse in the file, so the now-unusedusing System.Linq;is removed.Full solution builds with 0 warnings / 0 errors (
net10.0only) and all 3708 generator unit tests pass.Note
This PR body was drafted by Copilot on my behalf.