Search code examples
c#dockervisual-studio-2019visual-studio-debugging

Visual Studio 2019 C# Docker debugging process attach error


I'm trying to debug a Linux container that runs a C#/.NET 6.0 console application from Visual Studio 2019 (version 16.11.10).

When I use Debug / Attach to Process... to connect to my running container and attach to my process, I get the error:

Failed to launch debug adapter. Additional information may be available in the output window.

Unable to find debugger script at '/home/dockeruser/.vs-debugger'

For company security purposes, I'm running my container workloads as user dockeruser, but I can reproduce this when I adjust my Dockerfile to run as user root. The error message changes into

Unable to find debugger script at '/root/.vs-debugger'

Output shows

Unable to find debugger script at '/home/dockeruser/.vs-debugger'.


Initialization log:
Determining user folder on remote system...
Checking for existing installation of debugging tools...
Downloading debugger launcher...
Creating debugger installation folder: /home/dockeruser/.vs-debugger
Copying debugger launcher to /home/dockeruser/.vs-debugger/GetVsDbg.sh
Failed: Failed to copy files.
Unable to find debugger script at '/home/dockeruser/.vs-debugger'.
Failed: Unable to find debugger script at '/home/dockeruser/.vs-debugger'.
The program '[1] dotnet' has exited with code -1 (0xffffffff).

I can work around this by docker exec'ing a bash session on my container and running GetDbgVs.sh as detailed in https://stackoverflow.com/a/68950674/17273131, but its a pain to do - it feels like something is misconfigured.

I've already verified that my windows identity is a member of the windows docker-users group.


Solution

  • While not the answer I wanted, I've got a 1-liner shell workaround that I execute on my container when I want to debug attach with VS2019, once I know my <CONTAINER_NAME>. This may be useful to others with this problem.

    docker exec -u root <CONTAINER_NAME> sh -c "apt-get update && apt-get install wget -y"; docker exec <CONTAINER_NAME> sh -c "mkdir -p ~/.vs-debugger; wget https://aka.ms/getvsdbgsh -O ~/.vs-debugger/GetVsDbg.sh; chmod a+x ~/.vs-debugger/GetVsDbg.sh"

    • The first command installs wget as root
    • The second command downloads GetVsDbg.sh to ~/.vs-debugger