Repository navigation
Fix build-task LibraryImport generation with extensionReceiver - #1850
Merged
Jevan Saks (jevansaks) merged 1 commit intoOct 8, 2026
Merged
Conversation
Keep LibraryImport partial methods in a private nested partial class and forward extension members to them, preserving source-generated marshalling. Reuse the two-project integration test to reproduce #1825 with build-task generation and run it in both CI systems. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b8355a91-f69b-4c9c-9d44-86f5b49e32e5
Jevan Saks (jevansaks)
marked this pull request as ready for review
October 8, 2026 22:55
Sergio Pedri (Sergio0694)
approved these changes
Oct 8, 2026
Jevan Saks (jevansaks)
enabled auto-merge (squash)
October 8, 2026 23:35
Jevan Saks (jevansaks)
deleted the
jevansaks-extension-receiver-generation
branch
October 8, 2026 23:43
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.
Summary
Fixes #1825.
Keep
LibraryImportpartial methods in a private nested partial class, outside C# 14 extension blocks. Expose ordinary forwarding methods through the configured receiver, preserving source-generated marshalling, parameter modifiers, API documentation, and non-import attributes. Normal generation withoutextensionReceiveris unchanged.Reuse the existing two-project
sdk-roslyn5integration test rather than adding a new harness. Add the exactPInvoke.GetCurrentThreadId()call from the issue, plus void and pointer/friendly-overload calls. Run that same project withCsWin32RunAsBuildTask=truein both GitHub Actions and Azure Pipelines. Document build-task composition support.Generated code: before and after
Focused excerpts for
GetCurrentThreadIdfrom the integration test's extender, with file headers, XML documentation, unrelated attributes, and other members omitted for clarity.Before (broken)
The extension block is not a partial type, even though its containing class is partial. The compiler rejects the partial member (
CS0751,CS8795), and theLibraryImportgenerator cannot provide its implementation (SYSLIB1050).After (fixed)
The import now lives in a normal partial type, where the
LibraryImportgenerator can implement it. The extension member has a regular forwarding body, so callers still usePInvoke.GetCurrentThreadId()without disabling source-generated marshalling.Verification
SYSLIB1050,CS8795, andCS0751forGetCurrentThreadId.DisableRuntimeMarshalling=true, XML documentation generation, and multi-file output with a customNativeMethodshost name.ExtensionReceiverTestspassed.NU1510package-pruning warnings.