Dave Alger
Dave Alger

Reputation: 359

AspNetCore project gives System.IO.FileNotFoundException only on linux container

I've got a dotnet core project running AspNetCore webserver. I use a couple of other DLLs which is are fairly simple class libaries.

I can download the repository from git onto my windows PC, go in and run:

dotnet restore
dotnet run 

And everything works fine.

However if I do the same thing in a docker container based on microsoft/aspnetcore-build:1.0.7, I get the following error on an HTTP PUT:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLBKHRVH7OND": An unhandled exception was thrown by the application.
System.IO.FileNotFoundException: Could not load file or assembly 'KolData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

Now the file Koldata.dll does exist in the git repository and it's there in the bin/Debug/netcoreapp1.1 folder.

I can re-create the error in Windows by deleting the KolData.dll file in the build directory. So it seems to be that dotnet core on Linux cannot see that file, and I'm unsure why.

I've even tried replacing the DLL with a version built on the machine from source, and it still brings the same error.

One solution

I managed to get it working by changing the csproj file's target framework from:

<PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
</PropertyGroup> 

to:

 <PropertyGroup>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
  </PropertyGroup> 

This feels a bit strange since KolData.dll is running on 1.1 But now it runs without the error.

Upvotes: 1

Views: 3454

Answers (1)

user4625198
user4625198

Reputation:

You have to create Dockerfile and build docker image.

EDIT: An example of what Dockerfile should look like. The following file builds Visual Studio project and creates docker image.

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY WebApplication/WebApplication.csproj WebApplication/
RUN dotnet restore
COPY . .
WORKDIR /src/WebApplication
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

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

If you have already built your application include .dll in container with Dockerfile:

FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "application.dll"]

Build and run your app:

docker build -t application
docker run -d -p 8000:80 application

Building Docker Images for .NET Core Applications

Upvotes: 1

Related Questions