skip to Main Content

After updating to .NET 6 I get this error when running my ASP.NET app inside a Docker container:

An unhandled exception was thrown by the application.
System.IO.FileNotFoundException: Could not load file or assembly u0027Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeedu0027. The system cannot find the file specified.  File name: u0027Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeedu0027
at Cadmean.RPC.ASP.FunctionController.GetFunctionCall()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine]
...

Here is my Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

COPY . ./

RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DealCrackerBackend.dll"]

The library Newtonsoft.Json 13.0.1 is references from a different project (class library) in the solution. The referenced nuget package Cadmean.RPC is also using the same version of Newtonsoft.Json 13.0.1.

The app compiles and runs but when I make a request this happens.

The app works as before on macOS with .NET 6.0.100.

3

Answers


  1. I had the same issue and was also related to my unit test project. In my case, I’m using nUnit and it has Microsoft.NET.Test.Sdk version 17.1.0-preview and this references Newtonsoft.Json version 9, but all other projects have version 13.
    For now, just removed the unit test project from the solution

    Login or Signup to reply.
  2. Apparently, the issue is related to Newtonsoft.Json package and net6 but only in Docker (Linux) environment. We replaced that with System.Text.Json and it was resolved.

    Login or Signup to reply.
  3. I updates all packages in my solution and it`s fix my problem with Newtonsoft package restoring with docker.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search