问题
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