An assembly specified in the application dependencies manifest was not found: - c#

I developed application in asp.net-core 2.0 preview1.
I developed on windows with Visual Studio 2017.
Now I want to deploy it to Linux server using Docker.
I created Docker file:
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 44305
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Aplication.dll"]
After that running commands:
dotnet build -o obj/Docker/publish -c Release
dotnet publish -o obj/Docker/publish -c Release
docker build -t testapi-api .
docker run -p 44305:80 --name api testapi-api
Afer the last command run I am getting next error:
An assembly specified in the application dependencies manifest (Aplication.deps.json) was not found:
package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.0-preview1-final'
path: 'lib/netcoreapp2.0/Microsoft.AspNetCore.Antiforgery.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
manifest.win7-x64.xml;manifest.win7-x86.xml;manifest.osx-x64.xml;manifest.linux-x64.xml
I am new with asp.net-core and especially with Docker. So any help with this is great.

You need to specify -r linux-x64 parameter in dotnet publish command like that:
dotnet publish -o obj/Docker/publish -c Release -r linux-x64
This will make a standalone deployment.

Try to use this image "2.0.0-preview1". Basically change the first line to FROM microsoft/aspnetcore:2.0.0-preview1, if your local has preview 1 dotnet core.
If it not works, check your local dotnet core version, it it points to 2.0.0-preview2-final, then change all your references pointing to 2.0.0-preview2-final in csproj file, then use the 2.0.0-preview2 image. It would help you I hope.

Related

Running docker containers with .net6

I'm currently building an example of an API by using .net6 and I'm tracking to use docker to run the API.
My docker file looks like this:
# Grab the app package and create a new build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
# Let's add all the files into the app directory
WORKDIR /app
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
I created the image by running this command:
docker build -t binarythistle/dockerapi .
Now, I'm trying to run the image to create the container:
docker run -p 8000:80 dockerapi
But, I'm getting the following result:
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application 'DotNet.Docker.dll' does not exist.
* You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet-download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
Does anyone has any idea what can be done to solve this issue?
Site Note: I downloaded the .NET6.0 SDK macOS as recommended but I'm still having an issue. The project that I'm running with .net is a standard api project where the command that allowed me to create this is the following:
dotnet new webapi -n DockerAPI
There's no DotNet.Docker.dll within that directory that you're running dotnet.
The best way to solve this is to shell in to the container you've just created
docker run -it dockerapi bash
-it will make it an interactive processes
bash will change the ENTRYPOINT to be bash
once you've got a shell then run an ls command and see what files have been copied from the previous layer in the docker build
ls
I was also facing the same issue, however, it got it fixed after replacing below line in the docker file.
Old:
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
New:
ENTRYPOINT ["dotnet", "SampleWebApplication.dll"]
Use your_application_name.dll in place of SampleWebApplication.dll.
try running like this
ENTRYPOINT [ "./DotNet.Docker" ]

Unable to run self contained .net core 5.0 application

I have a .NET core 5.0 ASPNET Web API application. This application runs perfectly locally on Visual Studio.
Now I am trying to publish the self contained app using following command:
dotnet publish -c release testdb.sln --framework net5.0 --runtime linux-x64 /p:DebugType=None /p:DebugSymbols=false --nologo --self-contained true -v m
I am trying to run it over a Red Hat Linux image (image details below):
NAME="Red Hat Enterprise Linux Server"
VERSION="7.6 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.6"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.6 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.6:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.6
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.6"
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Red Hat Enterprise Linux Server release 7.6 (Maipo)
This is how my docker file looks like:
FROM testrepo.net/images/base/rhel:7.6
#published code is copied inside redhat folder
COPY redhat/ APP/
WORKDIR APP
RUN chmod +x /APP
RUN chmod +x testdb.dll
RUN chmod 777 /APP
ENTRYPOINT "./testdb.dll"
When I run this this image, I get error: ./testdb.dll: cannot execute binary file
I am not sure if this is due to invalid runtime I specified during publish command or something else.
changed RUN chmod +x testdb.dll to RUN chmod +x testdb
and changed ENTRYPOINT "./testdb.dll" to ENTRYPOINT "./testdb"
With these two changes I was able to fix the issue.

why dotnet 5 docker container fail in run time?

I have a dotnet5 Console application that is inside a solution and has dependencies on other sibling projects. I create the Docker file with visual studio tools and this is the Docker file:
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj", "src/MyProject/MyProject.Launcher/"]
COPY ["src/MyProject/MyProject.DataAccess/MyProject.DataAcess.csproj", "src/MyProject/MyProject.DataAccess/"]
COPY ["src/MyProject/MyProject.Service/MyProject.Service.csproj", "src/MyProject/MyProject.Service/]
COPY ["src/Domain/MyProject.Domain.Model/MyProject.Domain.Model.csproj", "src/Domain/MyProject.Domain.Model/"]
RUN dotnet restore "src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj"
COPY . .
WORKDIR "/src/src/MyProject/MyProject.Launcher"
RUN dotnet build "MyProject.Launcher.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProject.Launcher.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyProject.Launcher.dll"]
building image is ok and it added normally to my local image registry but when I try to run this image and create a container I am getting this error:
It was not possible to find any compatible framework version The
framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.
No frameworks were found.
You can resolve the problem by installing the specified framework
and/or SDK.
Use this as your base image:
FROM mcr.microsoft.com/dotnet/aspnet:5.0.0-buster-slim AS base
I Think You should check docker hub and search for .NET 5 SDK then install that image on your container then its will be fixed :
I Found Dotnet 3.1 SDK but try to find dotnet 5 SDK
I think after installation this error will be fix
Sorry For my Bad English
:)

xUNIT softwaretest with .NET CORE and Docker

I have a solution which contains two projects which has the following structure:
The project "TestWebApp" is a xUnit testproject and contains the software tests. The project "WebApplication" the software which should be tested with the testproject.
The software works fine but by now i would like to build a docker container which should be included in a gitlab ci-cd pipeline. My question contains two steps:
Should i build a container which contains the business application ("WebApplication") and the software test ("TestWebApp")? If this is the case how could i do that? How can i run the software test in the container? My Dockerfile looks like the following
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
COPY ["TestWebApp/TestWebApp.csproj", "TestWebApp/"]
# ------------------SOFTWARE TEST-------------------------------------------------------------
RUN dotnet restore "TestWebApp/TestWebApp.csproj"
RUN dotnet build "TestWebApp/TestWebApp.csproj" -c Release
RUN dotnet test --no-build -c Release --results-directory /testresults --logger "trx;LogFileName=test_result.xml" TestWebApp/TestWebApp.csproj
# ------------------WEB APP-------------------------------------------------------------
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
COPY --from=test /testresults .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
If i try it like the following dockerfile i get this error:
------
> FROM docker.io/library/test:latest:
------
failed to solve with frontend dockerfile.v0: failed to build LLB: failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
If I shouldn't build a container with business application and test - what would be the correct way?
It's fine to build them both in the docker container -- in fact, you'd want to do that; because you want your tests to run on every build of your CI/CD pipeline. The trick is they'll be in your initial docker image; but not in the one that gets deployed; and your Dockerfile code shows you're already doing that with the final.
The steps in your docker image should look a bit like this:
Build Project
Build Tests
Run Tests
Copy Deployable objects to deployable docker image
That final artifact, the deployable artifacts (without your tests) is what gets deployed; but this ensures your tests get run on every build.
So inyour answer, the only thing that's missing (at least from my eyeballing it) is a dotnet test for your test project between the build and final.

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.
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

Categories

Resources