Remote Debugging .Net Core Linux Docker Container - "The Current Source Is Different from the Version Built into .Dll"

Remote Debugging .NET Core Linux Docker Container - the current source is different from the version built into .dll

Tools->Options->Debugging->General, turn off "Require source files to exactly match the original version". Not ideal, but at least it hits the breakpoint set in the source code in VS2017.

Please let me know once you find out how to properly fix this.

Change ASP.NET API Docker port for debugging

In project folder "Properties\launchSettings.json" any debugging configurations such as; environment variables and profiles can be defined there.

note that the file only for debugging purposes if you add any environment variable here It will not affect published app.

An example 'launchSettings.json'

{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:3377",
"sslPort": 3378
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Dev": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "http://localhost:3377;https://localhost:3378"
},
"Prod": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"dotnetRunMessages": "true",
"applicationUrl": "http://localhost:3377;https://localhost:3378"
}
}
}

there is also profile for the Debugging on Docker;

"DockerDev": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"publishAllPorts": true
}

more detail: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-6.0#development-and-launchsettingsjson

Debugging an already-running Docker Linux .NET Core container with Visual Studio 2017

Having read Ankush's blog post, how about this:

If your service is based off of the microsoft/dotnet image, create a new Dockerfile based on the same image, and install the debugger, ssh and unzip.

FROM microsoft/dotnet

RUN apt-get update && apt-get -y install openssh-server unzip

RUN mkdir /var/run/sshd && chmod 0755 /var/run/sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin without-password/g' /etc/ssh/sshd_config
RUN sed -i 's/#StrictModes yes/StrictModes no/g' /etc/ssh/sshd_config

RUN service ssh restart

RUN mkdir /root/.vs-debugger && chmod 0755 /root/.vs-debugger
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v vs2017u1 -l /root/.vs-debugger/

EXPOSE 22

Build and push this to your registry.

docker build -t myregistry/dotnetdebugger .
docker push myregistry/dotnetdebugger

Next ensure that your service's build is outputting the PDB files as portable PDB files. See
Off-road Debugging of .NET Core on Linux or OS X from Visual Studio.

And ensure that the PDB files are included with the DLL files when you build your service's Docker image. Or better yet, volume mount an artefact directory with the PDB files in when you start your side car container.

Then when your container is running and you decide that you need to debug it, you can attach the debugger container as a side car container to the service:

docker run -d -p 10222:22 --pid container:<container name>  myregistry/dotnetdebugger

Then in Visual Studio, go to menu ToolsOptionsCrossplatformConnection Manager - and add a new connection. Specify the IP address or hostname of the sidecar container and 10222 as the port (the one in the docker run command), and root as the user without a password.

When you are done, you can simply shut down the sidecar container, leaving your service container running, and not exposing anything that is not needed for the general operation of your service.

How to access .NET Core webapi service launched from VSCode debugger within remote devcontainer from host machine

When the program is launched with the dotnet command, the app listens on http://[::]:80, but the debugger listens on http://localhost:5000.

Lord knows what I'm breaking by doing this, but changing

    "stackoverflow_devcontainers_ports_debug": {
...
"applicationUrl": "https://localhost:5001;http://localhost:5000",
...
}

to

    "stackoverflow_devcontainers_ports_debug": {
...
"applicationUrl": "https://localhost:5001;http://0.0.0.0:5000",
...
}

solved the issue (just working on HTTP for now).

If someone wants to educate me WHY this works, I'm all ears. Until then: I'll continue to solve problems by copying things that already work!

.NET Core CLR debugger VSDBG halts the application when attaching to a remote process in a Windows Docker container

It might be related to this GitHub issue:

Visual Studio Code hangs on breakpoint when attached to a remote debugger on a Windows Docker container #31070



Related Topics



Leave a reply



Submit