Skip to content

Fix: TryGenerateStructMarshallingMethod asserts on non-struct T in StructureMarshaler<T> - #130855

Merged
AaronRobinsonMSFT merged 3 commits into
mainfrom
copilot/fix-structure-marshaler-guard
Jul 17, 2026
Merged

AaronRobinsonMSFT merged 3 commits into
mainfrom
copilot/fix-structure-marshaler-guard

Conversation

Copilot AI commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

TryGenerateStructMarshallingMethod contained _ASSERTE(pStructMT->IsValueType()) which crashes the process in debug builds when tools like jit-dasm-pmi call RuntimeHelpers.PrepareMethod on a StructureMarshaler<object> (or any non-struct) instantiation.

Replace the assert with an early return false, causing the JIT to fall back to the default C# implementation rather than crashing.

Fixes #129649

Copilot AI requested review from Copilot and removed request for Copilot July 16, 2026 08:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
15 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 requested review from Copilot and removed request for Copilot July 16, 2026 08:54
Copilot AI changed the title [WIP] Fix StructureMarshaler to guard against non-struct type arguments Fix: TryGenerateStructMarshallingMethod asserts on non-struct T in StructureMarshaler<T> Jul 16, 2026
Copilot AI requested a review from jkotas July 16, 2026 08:55
Copilot AI temporarily deployed to copilot-pat-pool July 16, 2026 16:58 Inactive
Copilot AI temporarily deployed to copilot-pat-pool July 16, 2026 16:59 Inactive
@jkotas
jkotas marked this pull request as ready for review July 17, 2026 04:10
@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

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.

Pull request overview

This PR hardens CoreCLR’s struct marshalling stub generation so that invalid StructureMarshaler<T> instantiations with a reference-type T no longer trigger a VM debug assertion during intrinsic/transient IL generation (e.g., when RuntimeHelpers.PrepareMethod is used on such an instantiation).

Changes:

  • Replace a debug-only _ASSERTE(pStructMT->IsValueType()) with a runtime guard that returns false when T is not a value type.
  • Ensure the JIT falls back to the normal managed IL body for these invalid instantiations instead of attempting to generate struct marshalling IL (and asserting).

Comment thread src/coreclr/vm/dllimport.cpp Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings July 17, 2026 04:18
@jkotas
jkotas temporarily deployed to copilot-pat-pool July 17, 2026 04:18 — with GitHub Actions Inactive

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

/ba-g Failure is #130961

@AaronRobinsonMSFT
AaronRobinsonMSFT merged commit ce12d86 into main Jul 17, 2026
113 of 115 checks passed
@AaronRobinsonMSFT
AaronRobinsonMSFT deleted the copilot/fix-structure-marshaler-guard branch July 17, 2026 17:24
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — fbd526b8 Deployed Jul 17, 2026 by jkotas via pat_pool #15542
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

StructureMarshaler doesn't guard from non-struct type arguments

4 participants