2

I have created a Core 3.1 application that uses web services based on .net standard 2.0.

In the local development environment, everything works fine. Until I deploy it on UAT (IIS) 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 for a while, I found this:

Answered by Zhen Lan

First, copy the 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 publishing.

<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 ensured the file is in my deployment, but have still the same issue, what is going wrong and how can I fix the issue?

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137

1 Answers1

5

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

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

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

The way I fixed it, is 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 away.

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137