EventHubTriggerAttribute在名称空间'Microsoft.Azure.WebJobs'中不存在 [英] EventHubTriggerAttribute does not exists in namespace 'Microsoft.Azure.WebJobs'
问题描述
采取以下步骤在Visual Studio中创建Azure函数
Following steps are taken to create Azure Function in Visual Studio
- 创建新项目并选择
Azure Function
模板
- Create New Project and choose
Azure Function
template
- 选择Azure Function V2(.net代码)和
IoT Hub触发器
- 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名称空间'Microsoft.Azure.WebJobs'中不存在类型或名称空间名称'EventHubTriggerAttribute'(您是否缺少程序集引用?)DeviceMessageFunction_v2 C:\函数\DeviceMessageFunction_v2\Function1.cs
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:\Functions\DeviceMessageFunction_v2\Function1.cs
尝试添加引用,但没有运气
Tried add references, but no luck
以下是我的工具和框架详细信息
- Microsoft Visual Studio Enterprise 2017
- 版本15.7.4
- Microsoft .NET Framework
- 版本4.7.02558
- 已安装版本:企业版
- Azure App Service工具v3.0.0 15.0。 40608.0
- Azure函数和Web作业工具15.9.02046.0
- 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
推荐答案
使用V2函数时,您需要使用额外的NuGet软件包, Microsoft.Azure.WebJobs.Extensions.EventHubs
When using a V2 function you need to use an extra NuGet Package, Microsoft.Azure.WebJobs.Extensions.EventHubs
(来源)
这篇关于EventHubTriggerAttribute在名称空间'Microsoft.Azure.WebJobs'中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!