7

I used a v2 azure function (durable function) with custom dll (.net core 2.2) that calls a service and I get the following exception:

Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.4, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

In the debugging process, I can't step into the method and the exception is thrown without letting me inside it and I don't know exactly what tried to access that library. Putting manually the package from .nuget in the bin folder didn't work and the strange thing is that if a run the same code with a sample C# function it works.

Razvan Nitu
  • 71
  • 1
  • 1
  • 3

5 Answers5

8

fixed Nuget Install or Update System.Private.ServiceModel

Install-Package System.Private.ServiceModel -Version 4.7.0

https://www.nuget.org/packages/System.Private.ServiceModel/

Nader Gharibian Fard
  • 6,417
  • 4
  • 12
  • 22
  • I had a project runnitn on IIS using asp.net core 3.1. When website was published i got this error and fixed by installing it. – JohnnyJaxs Nov 06 '20 at 11:57
6

This issue is detailed here: https://github.com/dotnet/wcf/issues/2824

How I solved it was to download the nuget System.Private.ServiceModel

and add the following to my .csproj

<Target Name="CopySPSM" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.5.3\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
Paul Lorica
  • 703
  • 4
  • 6
3

I got this with a Blazor 3.1 app. Works fine locally, but, when deployed to Azure I get:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.ServiceModel

To fix it, in the Publish Profile, in Visual Studio, I changed the Target runtime from win-x86 to portable

enter image description here

Michael Washington
  • 2,744
  • 20
  • 29
1

There is a big thread about this on github. I added the PostBuild event as in that thread, but I was still struggling in the CI/CD build pipeline. In the end, I also added a cmd line script step in the build pipeline after the "Build Solution" step with the following code:

copy $(Agent.TempDirectory)\WebAppContent\bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll $(Agent.TempDirectory)\WebAppContent\bin\System.Private.ServiceModel.dll 

This solution does not seem that clean but it worked for me.

RickyG
  • 138
  • 6
0

Try to check in your cs.proj if System.Private.ServiceModel.dll is implemanted, if it's not the case you can refer to this work around : https://github.com/dotnet/wcf/issues/2824

Q.Rey
  • 305
  • 4
  • 18