dotnet / dotnet/roslyn

Creating a dynamic assembly with the same name as any assembly in the process causes debugging to fail within that assembly

Open
#79,612 2 comments 1 reaction 0 assignees View on GitHub
Area-Interactive untriaged
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**:
4.14.0-3.25326.11

**Steps to Reproduce**:

1. Debug an EXE in which a dynamic assembly is created with the same name as an assembly loaded into that process
2. Observe that upon creation of the assembly, the debugger exhibits internal compiler error.

```csharp
using System.Reflection;
using System.Reflection.Emit;

var (x, y) = (10, 20);
var asm = AssemblyBuilder.DefineDynamicAssembly(Assembly.GetExecutingAssembly().GetName(), AssemblyBuilderAccess.Run);
Console.WriteLine($"{x} + {y} = {x + y}");
```
Set a breakpoint on the `var asm` line, observe `x` and `y` beforehand, step over it, and observe the error.

I know this is a bit of a hysterical situation, but we shot ourselves with this foot-gun and spent a good long while inspecting things until we discovered the Modules window showing something like
"The real dll.dll" | Debuggable | PDB Path |
"The real dll" | Not Debuggable | No PDB Path |
where "The real dll" was the dynamic one.

Since it breaks the debugger, we thought to report rather than just live with our fix (obviously, slap a GUID on there).

**Expected Behavior**:
1. (Preferred) The debugger finds another/the next assembly to debug in (maybe not y'all, but this reports as a compiler error in VS).
2. .NET should disallow the creation of a dynamic assembly with the same name as another in the process (not y'all, but still... good to note).

**Actual Behavior**:
Internal compiler error in the debugger Auto/Local/Immediate windows

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the supplied C# program and debugger steps, then inspect how the Auto, Locals, and Immediate windows resolve the duplicate assembly shown in the Modules window. Compare behavior before and after AssemblyBuilder.DefineDynamicAssembly runs. Done means debugging continues without an internal compiler error when the dynamic assembly has the same name as a loaded assembly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.