Can't debug .NET Framework-targeted C# DLLs generated via Roslyn
- Dominant language
- TypeScript
- Stars
- 3.1k
- Forks
- 737
- Avg merge
- 17h 56m
- Merged PRs (30d)
- 21
Description
(Let me preface this by saying I'm aware that Desktop .NET C# debugging has limited support. That said...)
## Environment data
`dotnet --info` output: *dotnet not installed*
VS Code version: 1.22.2
C# Extension version: 1.14.0
## Steps to reproduce
1. Create and build a C# program that, using Roslyn, dynamically generates an assembly that appears to meet the requirements for limited debugging support in VS Code.
Code utilized to generate .DLL: (latest versions of Visual Studio and Roslyn Nuget packages)
```cs
Script script = CSharpScript.Create("int x = 0; x += 2;", ScriptOptions.Default
.WithReferences(new MetadataReference[] {
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile (typeof(Logger).Assembly.Location) // for Logger class
})
.WithImports(
"ScriptingWindow" // for static Logger class
, "System.Collections.Generic" // for IEnumerable goodies
).WithEmitDebugInformation(true));
var comp = script.GetCompilation().WithOptions(new CSharpCompilationOptions(outputKind: OutputKind.DynamicallyLinkedLibrary, platform: Platform.X64));
using (var modFS = new FileStream("UserCode.dll", FileMode.Create))
using (var pdbFS = new FileStream("UserCode.pdb", FileMode.Create))
{
EmitResult result = comp.Emit(modFS, pdbFS, options: new EmitOptions(false, DebugInformationFormat.PortablePdb));
if (result.Success)
Logger.Write("Compiled and saved!");
else
{
Logger.Write("Failed!");
}
}
```
2. Add dll to VS Code debug configuration (see launch.json)
3. Attempt to start debugging.
## Expected behavior
Debugger launches and attaches, allowing me to break when my application loads and launches the script contained in that DLL.
## Actual behavior
Receive error code 0x800700c1. Turning on engine logging reveals the following:
```
-> (C) {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"clr","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us"},"type":"request","seq":1}
-> (C) {"command":"launch","arguments":{"name":"UserCode","type":"clr","request":"launch","program":"C:\\Users\\jnorm\\Documents\\UserCode/UserCode.dll","args":[],"cwd":"C:\\Users\\jnorm\\Documents\\UserCode","console":"internalConsole","stopAtEntry":true,"logging":{"engineLogging":false},"justMyCode":false,"__sessionId":"651f6060-f602-45f6-8250-e964dfe7b6b8"},"type":"request","seq":2}
<- (E) {"seq":3,"type":"event","event":"output","body":{"category":"console","output":"-------------------------------------------------------------------\nYou may only use the Microsoft .NET Core Debugger (vsdbg) with\nVisual Studio Code, Visual Studio or Visual Studio for Mac software\nto help you develop and test your applications.\n-------------------------------------------------------------------\n"}}
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
<- (R) {"seq":4,"type":"response","request_seq":2,"success":true,"command":"launch"}
<- (E) {"seq":5,"type":"event","event":"initialized","body":{}}
-> (C) {"command":"setExceptionBreakpoints","arguments":{"filters":["all","user-unhandled"]},"type":"request","seq":4}
<- (R) {"seq":6,"type":"response","request_seq":4,"success":true,"command":"setExceptionBreakpoints"}
-> (C) {"command":"configurationDone","type":"request","seq":5}
```
## launch.json
```js
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "UserCode",
"type": "clr",
"request": "launch",
//"preLaunchTask": "build",
"program": "${workspaceFolder}/UserCode.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": true,
//"internalConsoleOptions": "openOnSessionStart"
"logging":{
"engineLogging": true
},
"justMyCode": false,
},
// remainder elided
}
```
Contributor guide
Assessment
This issue has not been assessed yet.