Service Model Assembly Error With Azure Functions V2+ (.net Core 2.1)

不想你离开。 提交于 2021-01-29 12:49:00

问题


I have been using azure function V2(.net core 2.1) in my azure function app. I have been using System.ServiceModel.Primitives nuget for my function App which uses ServiceBusEnvironment packages in it.

I am able to compile the code and run the function. While calling the function I get this runtime error.

   Could not load type 'System.ServiceModel.Channels.IBindingRuntimePreferences' 
from assembly 'System.ServiceModel, Version=4.0.0.0'

I googled up many things. But no luck.

I then tried by lowering my azure function from V2 to V1(.net Framework 4.7) and it started working again.

I need to know what I am doing wrong in case of V2. And how can I not get the error in case of V2? Is there any Resolution for the same?


回答1:


Microsoft has made available the relevant assemblies as packages on NuGet now.

System.ServiceModel.Primitives is the base package; add the others if necessary to your project.

I believe for loading System.ServiceModel.Channels you would need **System.ServiceModel.Http** installed in your project if it is not coming as a dependency, See if it works after installing correct version of System.ServiceModel.Http.

Adding the same "System.ServiceModel.Http" NuGet package to your app project by yourself so it would be referenced correctly. You can do this by using "Manage NuGet Package" menu item or just updating the packages.config file, for example

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="System.ServiceModel.Http" version="4.4.1" targetFramework="net461" />
  <package id="System.ServiceModel.Primitives" version="4.4.1" targetFramework="net461" />
</packages>

Additional reference:

https://github.com/dotnet/wcf/issues/2546

Hope it helps.




回答2:


I just came to a solution after lot of search that the azure function v2 is based on .net core and service bus libraries are not working well with v2(.net core)

The only solution which I found was switching to V1 as Azure functions V1 supports .net FrameWork classes.



来源:https://stackoverflow.com/questions/58728279/service-model-assembly-error-with-azure-functions-v2-net-core-2-1

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