Issue with System.Private.ServiceModel

Viewed 1775

I have created an Core 3.1 application that use web services based on .net standrad 2.0.

On local development environment every things works fine. Till I deploy it on UAT I get the following exception:

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()

After researching a while, I found this:

Answered by zhenlan

First, copy file %USERPROFILE%\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\unix\lib\netstandard2.0\system.private.servicemodel.dll to the root of your function app. If file is not found, you can download the nuget package from nuget.org.

Then, copy/paste below to your project's .csproj file. It will include S.P.SM.dll for build and publish.

<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>

I have also checked Protobuf-net has missing dependency System.Private.ServiceModel and Could not load file or assembly 'System.Private.ServiceModel' in Azure Function v2 with out much progress.

I have followed the answer and ensure the file is in my deployment, but have still the same issue, what is going wrong and how can I fix the issue?

1 Answers

While I made the question, I made some progress and wanted to share answer for those who might face the same issue.

As I understand this is used for web service part of my project, so in my local environment, it is served. But when I deploy it on UAT IIS, it does not have this by default.

So adding the file as I other answers mentioned in my question did not help. This could possibility has relation to have the right version, no knowledge about that.

The way I fixed it, I just installed the latest NuGet package via NuGet manager to my web application project.

<ItemGroup>
  <PackageReference Include="System.Private.ServiceModel" Version="4.7.0" />
</ItemGroup>

And after redeploying it on UAT, the issue was solved and it worked right a way.

Related