Skip to content

Convert hostfxr error-writer callback to an UnmanagedCallersOnly method - #56276

Merged
jkotas merged 3 commits into
mainfrom
copilot/convert-marshalled-delegate-to-unmanagedcallersonl
Sep 15, 2026
Merged

jkotas merged 3 commits into
mainfrom
copilot/convert-marshalled-delegate-to-unmanagedcallersonl

Conversation

Copilot AI commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

NETCoreSdkResolverNativeWrapper.GetGlobalJsonState installed its no-op hostfxr error writer via a managed delegate marshalled with Marshal.GetFunctionPointerForDelegate. Marshal.GetFunctionPointerForDelegate is a problematic API for both reliability and performance reasons. It should be avoided in modern interop where possible.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title Convert marshalled error-writer delegate to an UnmanagedCallersOnly method Convert hostfxr error-writer callback to an UnmanagedCallersOnly method Sep 11, 2026
Copilot AI requested a review from jkotas September 11, 2026 21:28
Copilot AI requested a review from jkotas September 11, 2026 23:28
@jkotas
jkotas marked this pull request as ready for review September 11, 2026 23:30
Copilot AI lite review requested due to automatic review settings September 11, 2026 23:30
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jkotas

jkotas commented Sep 11, 2026

Copy link
Copy Markdown
Member

This was found by dotnet/runtime#133675 . We are going to fix the bug in Marshal.GetFunctionPointerForDelegate too, but it would be best to avoid Marshal.GetFunctionPointerForDelegate in the first place.

Copilot AI 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.

🟡 Changes recommended

Restore the OS guard before creating SetupConfiguration to preserve non-Windows/Mono behavior.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Converts the modern hostfxr error-writer callback to an UnmanagedCallersOnly method while retaining the .NET Framework fallback.

Changes:

  • Adds a Cdecl unmanaged callback for modern .NET.
  • Retains delegate marshalling for .NET Framework.
  • Updates platform detection and resolver settings initialization.
File summaries
File Summary
src/Resolvers/Microsoft.DotNet.SdkResolver/VSSettings.cs Adjusts Visual Studio settings initialization; the platform guard should be retained.
src/Resolvers/Microsoft.DotNet.NativeWrapper/NETCoreSdkResolverNativeWrapper.cs Uses the unmanaged hostfxr error callback.
src/Resolvers/Microsoft.DotNet.NativeWrapper/Interop.cs Updates callback declarations and platform detection.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

@jkotas
jkotas requested a review from jkoritzinsky September 14, 2026 23:16
@jkotas
jkotas merged commit 1442bfe into main Sep 15, 2026
25 checks passed
@jkotas
jkotas deleted the copilot/convert-marshalled-delegate-to-unmanagedcallersonl branch September 15, 2026 02:41
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 16, 2026
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.

4 participants