我们在尝试将消息从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"
}
}
}
}
可能是造成此错误的原因。
请帮忙。
Azure Functions(当前版本v1)正在使用Microsoft.ServiceBus
客户端进行事件中心。您不需要从project.json
引用任何额外的NuGet包,只需这样做
#r "Microsoft.ServiceBus"
using Microsoft.ServiceBus.Messaging;
在您的Function脚本之上。
此外,我建议不要手动使用EventHubClient
。你应该尝试使用Output binding。