我创建了一个 Core 3.1 应用程序,它使用基于 .net 标准 2.0 的 Web 服务。
在本地开发环境中一切正常。在我将其部署到 UAT (IIS) 上之前,我收到以下异常:
Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.4, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Private.ServiceModel, Version=4.1.2.4, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at MyNameSpace.Service.TheService..ctor()
经过一段时间的研究,我发现this https://github.com/dotnet/wcf/issues/2824:
甄兰 回复
首先,复制文件%USERPROFILE%\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\unix\lib\netstandard2.0\system.private.servicemodel.dll
到函数应用程序的根目录。如果没有找到文件,您可以
从 nuget.org 下载 nuget 包。
然后,将以下内容复制/粘贴到项目的 .csproj 文件中。它将包括
S.P.SM.dll 用于构建和发布。
<ItemGroup>
<None Update="System.Private.ServiceModel.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CopySPSM" BeforeTargets="Build">
<Copy SourceFiles="System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
我也查过Protobuf-net 缺少依赖项 System.Private.ServiceModel https://stackoverflow.com/questions/53853817/protobuf-net-has-missing-dependency-system-private-servicemodel and 无法在 Azure Function v2 中加载文件或程序集“System.Private.ServiceModel” https://stackoverflow.com/questions/56984901/could-not-load-file-or-assembly-system-private-servicemodel-in-azure-function没有太大进展。
我已遵循答案并确保该文件位于我的部署中,但仍然存在相同的问题,出了什么问题以及如何解决该问题?