Skip to content

Fixed invoke on structs with not initialized byref fields - #127232

Merged
steveisok merged 4 commits into
dotnet:mainfrom
eterekhin:terekhin/mono-eval-ref-fields-fixes
Jul 6, 2026
Merged

steveisok merged 4 commits into
dotnet:mainfrom
eterekhin:terekhin/mono-eval-ref-fields-fixes

Conversation

@eterekhin

Copy link
Copy Markdown
Contributor

Hey, @thaystg! May I ask you to review that?

Repro steps

You can reproduce the problem on the following solution on Windows x64 VS 2026 (I used 18.4.3, but I think any 26 version is affected):
thinmono.zip

  1. Open thinmono\TestScriptLib\TestScriptLib.sln in VS and build it (if VS complains .NET 11 is not installed you can edit TestScriptLib.csproj to set the TargetFramework net11.0 -> net10.0)
  2. Set a breakpoint at TestFile.cs:28
  3. Go to thinmono\ThinMono.vcxproj and set the PathToDotnet to the path to runtime directory. Ensure the build.cmd-subset mono+libs is executed
  4. Open thinmono\ThinMono.sln in VS and run Debug AnyCPU configuration
  5. Once the native host is running attach to the app via VS's "Attach Unity Debugger" action with 9000 debug port specified, please see the attached screenshot
image 7. Once the managed debugger attaches the breakpoint set on the step 2 will be hit. Evaluate `default_struct.ReturnsSuccess()` in the Immediate Window

Expected behavior: "Success"
Actual behavior : "Internal evaluator error"

Description of the problem

During MyRefStruct default_struct buffering the ptr field value is not initialized and we buffer it as VALUE_TYPE_ID_NULL here. When the debugger calls a method on the struct we decode the struct and end up reaching this code path (as type = VALUE_TYPE_ID_NULL ). With my fix we consider this case as a not initialized by ref field and read the further related bytes (I found that the debugger passes only the byte and int back to Mono here)

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Apr 21, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @thaystg, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@eterekhin

Copy link
Copy Markdown
Contributor Author

Hey, @thaystg! May I ask you to review this change?

@steveisok
steveisok requested a review from thaystg June 8, 2026 11:59
@steveisok
steveisok merged commit 59ccb0c into dotnet:main Jul 6, 2026
76 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 7, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
## Repro steps

You can reproduce the problem on the following solution on Windows x64
VS 2026 (I used 18.4.3, but I think any 26 version is affected):

[thinmono.zip](https://github.com/user-attachments/files/26941236/thinmono.zip)

1. Open `thinmono\TestScriptLib\TestScriptLib.sln` in VS and build it
(if VS complains .NET 11 is not installed you can edit
`TestScriptLib.csproj` to set the `TargetFramework net11.0 -> net10.0`)
2. Set a breakpoint at `TestFile.cs:28`
3. Go to `thinmono\ThinMono.vcxproj` and set the `PathToDotnet` to the
path to `runtime` directory. Ensure the `build.cmd-subset mono+libs` is
executed
4. Open `thinmono\ThinMono.sln` in VS and run Debug AnyCPU configuration
5. Once the native host is running attach to the app via VS's "Attach
Unity Debugger" action with 9000 debug port specified, please see the
attached screenshot
<img width="940" height="508" alt="image"
src="https://github.com/user-attachments/assets/768514fe-93af-438b-94ac-f599bdfe9686"
/>
7. Once the managed debugger attaches the breakpoint set on the step 2
will be hit. Evaluate `default_struct.ReturnsSuccess()` in the Immediate
Window
  
**Expected behavior**: "Success" 
**Actual behavior** : "Internal evaluator error"

## Description of the problem
During `MyRefStruct default_struct` buffering the `ptr` field value is
not initialized and we buffer it as `VALUE_TYPE_ID_NULL`
[here](https://github.com/dotnet/runtime/blob/c837528c934554c5b7fed347ff613b7d9648d2d8/src/mono/mono/component/debugger-agent.c#L5102).
When the debugger calls a method on the struct we decode the struct and
end up reaching [this code
path](https://github.com/dotnet/runtime/blob/c837528c934554c5b7fed347ff613b7d9648d2d8/src/mono/mono/component/debugger-agent.c#L5733)
(as `type `= `VALUE_TYPE_ID_NULL `). With my fix we consider this case
as a not initialized by ref field and read the further related bytes (I
found that the debugger passes only the byte and int back to Mono
[here](https://github.com/mono/debugger-libs/blob/e7fbb713d156d11193ed404783ad6fe9c4042a6d/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs#L1289))

---------

Co-authored-by: Steve Pfister <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Debugger-mono community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants