question

AdamStachowicz-8288 avatar image
0 Votes"
AdamStachowicz-8288 asked ryanchill answered

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

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://docs.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 docs.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 docs.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 docs.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





vs-debuggingazure-webapps-developmentdotnet-ad
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
1 Vote"
ryanchill answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.