How to remote debugging .NET 5 Docker Container (App Service) in Azure from Visual Studio?

AdamStachowicz-8288 101 Reputation points
2021-04-27T21:33:46.097+00:00

I have dockerized .NET 5 app (Linux containers), hosted on Azure (as App Service), but I can't debug it from Visual Studio 2019 (Windows).

Attaching Debugger from Cloud Explorer gives me this error:

System.Runtime.InteropServices.COMException (0x89710023): Unable to connect to the Microsoft Visual Studio Remote Debugger named 'myapidev.azurewebsites.net'. The input was in an unexpected format or value.  
  
at Microsoft.WebTools.Azure.VS.Operations.IDebuggerInternal120.ConnectToServer(String szServerName, VsDebugRemoteConnectOptions[] pConnectOptions, CONNECT_REASON ConnectReason, Int32 fIncrementUsageCount, IDebugCoreServer3& ppServer)  
at Microsoft.WebTools.Azure.VS.Operations.RemoteDiagnosticsSessionBase`1.ConnectToServer(String site, String user, String password)  

Attaching Debugger from Debug -> Attach to Process (Connection type: Default, target: myapidev.azurewebsites.net:4024):
it asks for credentials, so I downloaded Publish Profile, but login as $MyUserNameFromPublish, .\$MyUserNameFromPublish or $MyUserNameFromPublish\$MyUserNameFromPublish not working (Unable to connect to 'myapidev.azurewebsites.net:4024'. The input was in an unexpected format or value.)

INFO:

App is published with Debug configuration (dotnet publish "My.Api.csproj" -c Debug)

I'm using mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim Docker image

Enable Just My Code option is disabled in Visual Studio.

In documentation for App Service, required ports for remote debugging are opened by default: https://learn.microsoft.com/en-us/azure/app-service/networking-features#app-service-ports

And also in Development Tools -> Advanced Tools in Azure I see APPSETTING_REMOTEDEBUGGINGVERSION = 16.0.30709.132 and APPSVC_REMOTE_DEBUGGING = TRUE.
Adding WEBSITES_PORT environment with 4024 or 3702;4025;4024;4022;4020 also doesn't help...

I added -p 4020:4020 -p 4022:4022 -p 4024:4024 in Settings -> General settings -> Startup Command in App Service and now my docker run have this command, but I still have this same error...

I can also see remoteDebuggingEnabled set to true and remoteDebuggingVersion to VS2019 at https://resources.azure.com/ (in my app_name/config/web).

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base  
  
### For learn.microsoft.com: You can delete next lines for RUN command if you are not using System.Drawing in your project  
# Install System.Drawing native dependencies  
RUN apt-get update \  
    && apt-get install -y --allow-unauthenticated \  
        libc6-dev \  
        libgdiplus \  
        libx11-dev \  
     && rm -rf /var/lib/apt/lists/*  
  
WORKDIR /app  
EXPOSE 80  
EXPOSE 443  
  
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build  
WORKDIR /src  
  
ARG FEED_USERNAME  
ARG FEED_ACCESSTOKEN  
### For learn.microsoft.com: You can delete next line if you are not using private NuGet repositories/feeds  
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS \  
    "{\"endpointCredentials\": [{\"endpoint\":\"https://company.pkgs.visualstudio.com/_packaging/MyFeed/nuget/v3/index.json\", \"username\":\"${FEED_USERNAME}\", \"password\":\"${FEED_ACCESSTOKEN}\"}]}"  
  
### For learn.microsoft.com: You can delete next line if you are not using private NuGet repositories/feeds  
# Credential Provider: https://github.com/Microsoft/artifacts-credprovider  
RUN curl -L https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash  
  
COPY ["My.Api/My.Api.csproj", "My.Api/"]  
RUN dotnet restore "My.Api/My.Api.csproj"  
COPY . .  
WORKDIR "/src/My.Api"  
  
FROM build AS publish  
RUN dotnet publish "My.Api.csproj" -c Debug -o /app/publish  
  
FROM base AS final  
WORKDIR /app  
COPY --from=publish /app/publish .  
  
# Remote debugging. Open ports: 4025 for 32-bit process for VS 2019, 4024 for VS 2019, 4022 for VS 2017 and 4020 for VS 2015  
# 3702 is required for remote debugger discovery  
EXPOSE 3702 4025 4024 4022 4020  
  
ENTRYPOINT ["dotnet", "My.Api.dll"]  

Desired behavior:
I can connect to my app service debugger from Cloud Explorer

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,644 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
967 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,405 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 27,031 Reputation points Microsoft Employee
    2021-04-28T20:25:12.16+00:00

    Hi @AdamStachowicz-8288 ,

    I made some inquiries regarding remote debugging Linux deployed containers from Visual Studio. Currently, this isn't supported from the Cloud Explorer. The good news is that this is feature is being worked on and will make it into a future Visual Studio update.

    1 person found this answer helpful.