Skip to content

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Jul 8, 2025

Ran into this while testing some some sample code. When a collection marshaller does not conform to the correct shape and an element marshaller is specified, we crash the generator with a NullRef.

Filed #117448 to track this.

Copy link
Contributor

@Copilot Copilot AI left a comment

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 introduces a new test snippet that triggers a generator crash when a collection marshaller is mis-shaped, but leaves the test commented out until the issue is resolved.

  • Added ImproperCollectionWithMarshalUsingOnElements snippet in CodeSnippets.cs.
  • Added commented-out test entry in CompileFails.cs for the new snippet.

Reviewed Changes

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

File Description
CompileFails.cs Commented new test case for improper collection marshalling that currently crashes the generator
CodeSnippets.cs Defined ImproperCollectionWithMarshalUsingOnElements snippet to reproduce the crash
Comments suppressed due to low confidence (3)

src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CompileFails.cs:60

  • [nitpick] Add a TODO with a reference to the GitHub issue tracking this crash so it’s clear when to re-enable the test (e.g., // TODO: re-enable once dotnet/runtime#12345 is fixed).
            // Bug: crashes

src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CompileFails.cs:61

  • The test for the improper collection scenario is currently disabled, leaving this crash case unverified; consider adding a placeholder assertion or a skipping mechanism that documents expected behavior until the bug is fixed.
            // yield return new[] { ID(), CodeSnippets.ImproperCollectionWithMarshalUsingOnElements };

src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/CompileFails.cs:61

  • The commented test uses new[] without specifying the expected DiagnosticResult array or matching the object[] signature used elsewhere. Use new object[] { ID(), CodeSnippets.ImproperCollectionWithMarshalUsingOnElements, Array.Empty<DiagnosticResult>() } to match the helper method signature.
            // yield return new[] { ID(), CodeSnippets.ImproperCollectionWithMarshalUsingOnElements };

Copy link
Contributor

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

…rtGenerator.UnitTests/CompileFails.cs

Co-authored-by: Aaron Robinson <[email protected]>
@jtschuster jtschuster merged commit f8b5e9c into dotnet:main Jul 9, 2025
89 of 94 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants