Azure Functions V2+ (.net Core 2.1) 的服务模型组装错误

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

我一直在我的 azure function 应用程序中使用 azure function V2(.net core 2.1)。 我一直在为我的函数应用程序使用 System.ServiceModel.Primitives nuget,其中使用 ServiceBusEnvironment 包。

我能够编译代码和运行函数。 调用该函数时出现此 运行 时间错误。

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

我用谷歌搜索了很多东西。但是运气不好。

然后我尝试将我的 azure 函数从 V2 降低到 V1(.net Framework 4.7),它又开始工作了。

我需要知道在 V2 的情况下我做错了什么。如果是 V2,我怎么能不出错?是否有相同的解决方案?

Microsoft 现已在 NuGet 上以包的形式提供相关程序集。

System.ServiceModel.Primitives是基础包;如有必要,将其他人添加到您的项目中。

我相信要加载 System.ServiceModel.Channels 你需要在你的项目中安装 **System.ServiceModel.Http** 如果它不是依赖项, 安装正确版本的 System.ServiceModel.Http.

后查看它是否有效

自己将相同的 "System.ServiceModel.Http" NuGet 包添加到您的应用程序项目中,以便正确引用它。您可以通过使用 "Manage NuGet Package" 菜单项或仅更新 packages.config 文件来执行此操作,例如

<?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>

附加参考:

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

希望对您有所帮助。

经过大量搜索后我才找到一个解决方案,即 azure 函数 v2 基于 .net 核心,而服务总线库不能很好地与 v2(.net 核心)一起工作

我找到的唯一解决方案 是切换到 V1,因为 Azure 函数 V1 支持 .net FrameWork 类。