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

  • Docker
  • .NET Core 1.1
  • Visual studio 2017
  • .NET Core Debugger (clrdbg)

I get the following error:

"The breakpoint will not currently be hit. A copy of TokenController.cs was found in TSL.Security.Service.dll, but the current source code is different from the version built into the TSL.Security.Service.dll." 

enter image description here

I will get step-by-step how I create the .NET Core Docker image and run the Container instance from this image and then connect to the remote device with Visual Studio 2017, my Dockerfile.debug is at the bottom of my question:

  • on my host docker cd ~/repos/api.security // a git repository
  • git pull // pull the latest code from git for a .NET Core project
  • dotnet restore
  • dotnet publish // without any other args publishes with .pdbs
  • docker build -t tsl.api.security.image.debug -f Docker.debug .
  • docker run -d -p 8080:5000 -p 10222:22 --name=tsl.api.security.container.debug -t tsl.api.security.image.debug // start and map my .NET Core Webapi in the container on port 5000 to host port 8080 and the ssh card in the container, port 22, on port 10222 on the host
  • docker exec -it tsl.api.security.container.debug bash // terminal in starting the container from the host
  • /usr/sbin/sshd // start sshd

Ok, now that the container is ready to remove debugs using ssh with Visual Studio 2017, on my machine with Visual Studio 2017:

  • get the latest code from git
  • open .sln with Visual Studio 2016
  • Assembly in debug mode
  • Go to Tools -> Options -> Cross-platform and my SSH-Remote: enter image description here
  • CTRL + ALT + P // joins the process
  • Choose a connection type β†’ SSH enter image description here
  • Select Managed (.NET Core for Unix) enter image description here

And viola! I have my problem: enter image description here

If we look at /app in my Docker container, we will see pdbs: enter image description here

And the source code is the same as demonstrating the git pull steps in explaining the workflow.

Not sure where to go from here ...

Here is my Dockerfile.debug file:

 # Use the standard Microsoft ASP.NET Core container FROM microsoft/aspnetcore # File Author / Maintainer MAINTAINER Brian Ogden WORKDIR / RUN apt-get update && apt-get install -y unzip RUN apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:password' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed ' s@session \s*required\s* pam_loginuid.so@session optional pam_loginuid.so@g ' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile #install CLRDBG, Microsoft new cross-platform command line debugger used for debugging code running on .NET Core RUN curl -sSL https://aka.ms/getclrdbgsh | bash /dev/stdin vs2015u2 ~/clrdbg # Copy our code from the "/src/MyWebApi/bin/Debug/netcoreapp1.1/publish" folder to the "/app" folder in our container WORKDIR /app COPY ./src/TSL.Security.Service/bin/Debug/netcoreapp1.1/publish . # Expose port 80 for the Web API traffic ENV ASPNETCORE_URLS http://+:5000 EXPOSE 5000 22 ENTRYPOINT ["dotnet", "TSL.Security.Service.dll"] 
+5
source share
1 answer

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

Please let me know as soon as you know how to fix it.

+6
source

Source: https://habr.com/ru/post/1268608/


All Articles