dotnet / dotnet/vscode-csharp

`DebuggerTypeProxy` generates an invalid expression when runtime and static types differ

Open
#9,108 0 comments 0 reactions 0 assignees View on GitHub
Bug Debugger Debugger-ExpressionEvaluation
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
17h 56m
Merged PRs (30d)
21

Description

Type: Bug

## Issue Description ##
When expression runtime type is different from its static type, and runtime type define `DebuggerTypeProxy`, then that proxy displayed in Locals view, but interacting with proxies' properties (_Copy Value_, _Copy as Expression_) produce incorrect result.

## Steps to Reproduce ##
```csharp
using System.Diagnostics;

namespace Test;

public static class Program
{
public static void Main()
{
Base v = new Derived();
} // breakpoint here
}

public class Base { }

[DebuggerTypeProxy(typeof(DebugProxy))]
public class Derived : Base { }

public class DebugProxy(Derived instance)
{
public string Property => "Value";
}
```
Image

## Expected Behavior ##
Copy Value should copy `Value`.
Copy as Expression should copy `new Test.DebugProxy((Derived)v).Property`.

## Actual Behavior ##
Copy Value copy `error CS1503: Argument 1: cannot convert from 'Test.Base' to 'Test.Derived'`.
Copy as Expression copy `new Test.DebugProxy(v).Property`.

Extension version: 2.130.5
VS Code version: Code 1.113.0 (cfbea10c5ffb233ea9177d34726e6056e89913dc, 2026-03-24T15:07:18+01:00)
OS version: Windows_NT x64 10.0.28000
Modes:

## Environment Information ##
**VSCode version**: 1.113.0
**C# Extension**: 2.130.5
**Using OmniSharp**: false

Dotnet Information

```
.NET SDK:
Version: 10.0.201
Commit: 4d3023de60
Workload version: 10.0.200-manifests.0793c108
MSBuild version: 18.3.0-release-26153-122+4d3023de6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.28000
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.201\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.5
Architecture: x64
Commit: a612c2a105

.NET SDKs installed:
10.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found
```

Visual Studio Code Extensions

|Extension|Author|Version|Folder Name|
|---|---|---|---|
|csharp|ms-dotnettools|2.130.5|ms-dotnettools.csharp-2.130.5|
|vscode-dotnet-runtime|ms-dotnettools|3.0.0|ms-dotnettools.vscode-dotnet-runtime-3.0.0|;

C# Settings

|Setting|Value|
|---|---|
|preferCSharpExtension|false|
|compilerDiagnosticScope|openFiles|
|analyzerDiagnosticScope|openFiles|
|enableXamlTools|true|
|useServerGC|true|;

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.