问题
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.
回答1:
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>
回答2:
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/
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/56984901/could-not-load-file-or-assembly-system-private-servicemodel-in-azure-function