在Azure Functions中引用EventHub程序集时出错

时间:2018-03-05 13:03:15

标签: azure azure-eventhub

我们在尝试将消息从Azure HTTP触发器功能发布到Event Hub时收到以下错误。我没有包含完整的代码,因为当我包含命名空间本身时,我收到了错误。

>  2018-03-05T12:49:47.912 [Info] Function started
> (Id=da357e2a-3604-4dd1-b199-646ffcc91469)
>     2018-03-05T12:49:47.912 [Error] Function compilation error
>     2018-03-05T12:49:47.912 [Error] run.csx(2,23): error CS0234: The type or namespace name 'EventHubs' does not exist in the namespace
> 'Microsoft.Azure' (are you missing an assembly reference?)
>     2018-03-05T12:49:47.928 [Error] Exception while executing function: Functions.EventsHandler. Microsoft.Azure.WebJobs.Script:
> Script compilation failed.
>     2018-03-05T12:49:47.944 [Error] Function completed (Failure, Id=da357e2a-3604-4dd1-b199-646ffcc91469, Duration=29ms)

这是我的功能代码

using System.Net;
using Microsoft.Azure.EventHubs;
using System.Text;
using System.Threading.Tasks;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{// variable declarations
    private static EventHubClient eventHubClient;
    private const string EhConnectionString = "{Event Hubs connection string}";
    private const string EhEntityPath = "{Event Hub path/name}";

   }

我的project.json

{"frameworks":
    {"net461":
        {"dependencies":
            {"Microsoft.Azure.EventHubs":"1.1.0"
            }
        }
    }
}

出现此错误的原因可能是什么。

请帮忙。

1 个答案:

答案 0 :(得分:1)

Azure Functions(当前版本v1)正在将app.use(express.static(path.join(appRoot.path, 'dist')));客户端用于事件中心。您不需要为Microsoft.ServiceBus引用任何额外的NuGet包,只需执行

project.json

在您的Function脚本之上。

此外,我建议不要手动使用#r "Microsoft.ServiceBus" using Microsoft.ServiceBus.Messaging; 。您应该尝试使用C# supports this as a special case代替。