命名空间“Microsoft.Azure.WebJobs"中不存在 EventHubTriggerAttribute [英] EventHubTriggerAttribute does not exists in namespace 'Microsoft.Azure.WebJobs'
问题描述
在 Visual Studio 中创建 Azure Function 的步骤如下
- 创建新项目并选择
Azure Function
模板
- 选择 Azure Function V2 (.net code) 和
IoT Hub Trigger
已生成代码,但存在引用错误.
使用 IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;使用 Microsoft.Azure.WebJobs;使用 Microsoft.Azure.WebJobs.Host;使用 Microsoft.Azure.EventHubs;使用 System.Text;使用 System.Net.Http;使用 Microsoft.Extensions.Logging;命名空间 DeviceMessageFunction_v2{公共静态类 Function1{私有静态 HttpClient 客户端 = 新 HttpClient();[函数名称(函数 1")]public static void Run([IoTHubTrigger("messages/events", Connection = "")]EventData message, ILogger log){log.LogInformation($"C# IoT Hub 触发函数处理了一条消息:{Encoding.UTF8.GetString(message.Body.Array)}");}}}
<块引用>
CS0234 名称空间Microsoft.Azure.WebJobs"中不存在类型或名称空间名称EventHubTriggerAttribute"(您是否缺少程序集引用?)DeviceMessageFunction_v2 C:FunctionsDeviceMessageFunction_v2Function1.cs
尝试添加引用,但没有成功
这是我的工具和框架详情
- Microsoft Visual Studio 企业版 2017
- 版本 15.7.4
- Microsoft .NET 框架
- 版本 4.7.02558
- 安装版本:企业版
- Azure 应用服务工具 v3.0.0 15.0.40608.0
- Azure Functions 和 Web 作业工具 15.9.02046.0
使用 V2 功能时,您需要使用额外的 NuGet 包,Microsoft.Azure.WebJobs.Extensions.EventHubs
(来源)
Following steps are taken to create Azure Function in Visual Studio
- Create New Project and choose
Azure Function
template
- Select Azure Function V2 (.net code ) and
IoT Hub Trigger
Code generated but with reference errors.
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Microsoft.Azure.EventHubs; using System.Text; using System.Net.Http; using Microsoft.Extensions.Logging; namespace DeviceMessageFunction_v2 { public static class Function1 { private static HttpClient client = new HttpClient(); [FunctionName("Function1")] public static void Run([IoTHubTrigger("messages/events", Connection = "")]EventData message, ILogger log) { log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}"); } } }
CS0234 The type or namespace name 'EventHubTriggerAttribute' does not exist in the namespace 'Microsoft.Azure.WebJobs' (are you missing an assembly reference?) DeviceMessageFunction_v2 C:FunctionsDeviceMessageFunction_v2Function1.cs
Tried add references, but no luck
Here is my tools and framework details
- Microsoft Visual Studio Enterprise 2017
- Version 15.7.4
- Microsoft .NET Framework
- Version 4.7.02558
- Installed Version: Enterprise
- Azure App Service Tools v3.0.0 15.0.40608.0
- Azure Functions and Web Jobs Tools 15.9.02046.0
When using a V2 function you need to use an extra NuGet Package, Microsoft.Azure.WebJobs.Extensions.EventHubs
(Source)
这篇关于命名空间“Microsoft.Azure.WebJobs"中不存在 EventHubTriggerAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!