Could not load file or assembly 'System.Private.ServiceModel' in Azure Function v2

好久不见. 提交于 2020-08-07 03:44:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!