EventHubTriggerAttribute does not exists in namespace 'Microsoft.Azure.WebJobs'

拈花ヽ惹草 提交于 2019-12-10 17:17:40

问题


Following steps are taken to create Azure Function in Visual Studio

  1. Create New Project and choose Azure Function template

  1. Select Azure Function V2 (.net code ) and IoT Hub Trigger

  1. 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:\Functions\DeviceMessageFunction_v2\Function1.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

回答1:


When using a V2 function you need to use an extra NuGet Package, Microsoft.Azure.WebJobs.Extensions.EventHubs

(Source)



来源:https://stackoverflow.com/questions/54240143/eventhubtriggerattribute-does-not-exists-in-namespace-microsoft-azure-webjobs

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