我有一个Azure功能,它通过IBinder访问通知中心,如下所示: -
public static async Task Run(string msg, IBinder binder, TraceWriter log)
{
var genericInputMessage = JsonConvert.DeserializeObject<GenericInputMessage>(msg);
string devicetag = "deviceid:" + genericInputMessage.device;
var attribute = new NotificationHubAttribute
{
ConnectionStringSetting = "NotificationHubConnection",
HubName = "NotificationHubName",
TagExpression = devicetag
};
IAsyncCollector<Notification> notifications = binder.Bind<IAsyncCollector<Notification>>(attribute);
...
...
}
通过Azure门户网站完成编译并正常工作。
当我在使用VS2017(版本15.3.3)的预编译Azure函数中使用相同的代码并在本地运行时,我在调用binder.Bind时遇到异常。
给出的例外是......
[23/09/2017 16:47:07] A ScriptHost error has occurred
[23/09/2017 16:47:07] Exception while executing function: DataProcessor. Microsoft.Azure.WebJobs.Host: No binding found for attribute 'Microsoft.Azure.WebJobs.NotificationHubAttribute'.
我预编译的Azure功能的代码如下: -
public static async Task Run([EventHubTrigger("EventHubName", Connection = "EventHubConnection")]string msg, IBinder binder, TraceWriter log)
{
var genericInputMessage = JsonConvert.DeserializeObject<GenericInputMessage>(msg);
string devicetag = "deviceid:" + genericInputMessage.device;
var attribute = new NotificationHubAttribute
{
ConnectionStringSetting = "NotificationHubConnection",
HubName = "NotificationHubName",
TagExpression = devicetag
};
IAsyncCollector<Notification> notifications = binder.Bind<IAsyncCollector<Notification>>(attribute);
...
...
}
我正在使用以下NuGet包: -
关于可能导致这种情况的任何想法?
答案 0 :(得分:0)
这可能最终可能是由于运行时未正确检测Notification Hub使用情况(因此未加载扩展程序)。通常,我们可以扫描Function.json来确定需要什么 - 但IBinder的使用更加不透明。
作为一种解决方法,您可以添加引用Notification Hub绑定的功能吗?它可以是手动触发器,不需要实际调用。
这与https://github.com/Azure/azure-webjobs-sdk-script/issues/1637
有关