I'm trying to build my .net core project onto a docker container but it seems like it can't find Newtonsoft.Json which I thought was included in the asp.net core
Here is my docker file:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 58373
EXPOSE 44370
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["TestCode/TestCode.csproj", "TestCode/"]
RUN dotnet restore "TestCode/TestCode.csproj"
COPY . .
WORKDIR "/src/TestCode"
RUN dotnet build "TestCode.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "TestCode.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TestCode.dll"]
I'm getting the following error when trying to build Error Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
The problem here is that – unlike .NET projects for the regular .NET Framework – the build process for a .NET Core project ( dotnet build) does not copy any dependencies into the output folder. If you look into bin\Debug etcoreapp1.0 you’ll find no Newtonsoft.Json.dll file there. There’s a second problem (or more an inconvenience).
This error mainly occurs when the DNN website has an incorrect version of the Newtonsoft.Json package in its configuration. At Bobcares, we often get requests to fix DNN errors, as a part of our Server Management Services. Today, let’s see how our Support Engineers fix the error for our customers. When does the Newtonsoft.Json Error occur?
If the Newtonsoft.Json Package is outdated then the ‘Could not load file or assembly Newtonsoft.Json’ error may appear. So we check the version of the Newtonsoft.Json Package and update it to the latest one.
Create a Dockerfile for an ASP.NET Core application Method 1: Create a Dockerfile in your project folder. Add the text below to your Dockerfile for either Linux or Windows Containers. The tags below are multi-arch meaning they pull either Windows or Linux containers depending on what mode is set in Docker Desktop for Windows.
In my case, When used JsonProperty
in a class,
Visual Studio intellicode auto-filled,
using Newtonsoft.Json;
Then during docker build
,
warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json". Check to make sure the assembly exists on disk.
When I checked, found out that the Visual Studio added an Assembly Reference to Newtonsoft.Json
(you can find this by expanding Dependencies node in the solution explorer in Visual Studio). And I was using Linux images.
So in order to solve this, I removed the Assembly Reference, and added nuget package Newtonsoft.Json
, then the docker build
was successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With