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
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 andnet6
but only in Docker (Linux) environment. We replaced that withSystem.Text.Json
and it was resolved.I updates all packages in my solution and it`s fix my problem with Newtonsoft package restoring with docker.