无法在 Docker 容器、ASP.NET 6 中加载文件或程序集 Newtonsoft.Json

Але*_*ков 6 .net c# asp.net docker

更新到 .NET 6 后,在 Docker 容器内运行 ASP.NET 应用程序时出现此错误:

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]
...
Run Code Online (Sandbox Code Playgroud)

这是我的 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"]
Run Code Online (Sandbox Code Playgroud)

库 Newtonsoft.Json 13.0.1 是来自解决方案中不同项目(类库)的引用。引用的 nuget 包 Cadmean.RPC 也使用相同版本的 Newtonsoft.Json 13.0.1。

该应用程序编译并运行,但是当我发出请求时,就会发生这种情况。

该应用程序在 .NET 6.0.100 的 macOS 上像以前一样运行。

小智 1

我更新了解决方案中的所有软件包,它解决了使用 docker 恢复 Newtonsoft 软件包的问题。