0
votes

I am trying to run a multi container service locally built from docker-compose. If I debug the service from the dockerfile the debugger works fine, but when I debug using docker-compose and I try to evaluate an object it doesn't work. My project uses .net core 3

In particular I'm looking at the startup class. When I put a breakpoint on the constructor I can evaluate the configuration object. But the area that I'm interested in is the Configure method. When I put the breakpoint where the code checks the environment I get the following message.

The name 'env' does not exist in the current context

I can successfully evaluate this object when I debug directly from my dockerfile. But I what to be able to fully debug my entire application that is split into multiple service, by debugging using the docker-compose file.

Is there something that I'm missing or somewhere Ive made a mistake?

Relevant extracts from my code are below.

public class Startup
{
   private IConfiguration Configuration { get; }
    
   public Startup(IConfiguration configuration)
   {
        Configuration = configuration;
   }

   public void ConfigureServices(IServiceCollection services)
   {
       ....
   }

   public void ConfigureContainer(ContainerBuilder builder)
   {
       ...
   }

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
      if (env.IsDevelopment())
      {
          ...
          context.Database.Migrate();
      }

      app.Run(async (context) =>
      {
          await context.Response.WriteAsync("Hello World!");
      });
    }
  }

I have tried a few things so far to fix this. These have been make sure that I have Rider updated, use the .Net Core 3 sdk docker image and I've made sure that the dotnet build command uses the Debug configuration.

There are a few other things that I have read about that seem more relevant to optimizations that VS makes when building from docker-compose, so I'm not sure if these apply to Rider.

My dockerfile is

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT Development
EXPOSE 85
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY EventService/EventService.csproj EventService/
RUN dotnet restore "EventService/EventService.csproj"
COPY . .
WORKDIR "/src/EventService"
RUN dotnet build "EventService.csproj" -c Debug -o /app/build

FROM build AS publish
RUN dotnet publish "EventService.csproj" -c Debug -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EventService.dll"]

and my docker-compose is

version: '3.4'

services:
  eventapi:
    image: ${DOCKER_REGISTRY-}eventapi
    build:
      context: .
      dockerfile: EventApi/Dockerfile
    networks:
      - backend

  eventservice:
    image: ${DOCKER_REGISTRY-}eventservice
    build:
      context: .
      dockerfile: EventService/Dockerfile
    networks:
      - backend
    depends_on:
      - sql.db

  sql.db:
    image: "microsoft/mssql-server-linux:2017-latest"
    environment:
      SA_PASSWORD: "myBigDevPassword!"
      ACCEPT_EULA: "Y"
    ports:
      - "1433:1433"
    networks:
      - backend
networks:
  backend: {}
1

1 Answers

0
votes

This ended up being a simple fix. I just had to update Rider to the latest version. There was a bug that caused this issue with this when it was first released as a feature in Rider.