简体   繁体   中英

Could not load file or assembly Newtonsoft.Json in Docker container, ASP.NET 6

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=30ad4fe6b2a6aeed\u0027. The system cannot find the file specified.  File name: \u0027Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\u0027
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.

I updates all packages in my solution and it`s fix my problem with Newtonsoft package restoring with docker.

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

Apparently, the issue is related to Newtonsoft.Json package and net6 somehow. We replaced that with System.Text.Json and it was resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM