预编译的 Azure 函数 StorageTableInput 绑定不起作用
Precompiled Azure Function StorageTableInput binding not working
我正在尝试使用“将 .NET class 库发布为函数应用程序”将 Azure 函数应用程序转换为预编译版本 blog post 来自 Donna Malayeri。
我使用的计时器触发器有一个使用类型化对象的 StorageTable 输入绑定。该对象继承自“TableEntity”。虽然门户中的版本没有任何问题,但我的预编译版本抛出以下错误:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ScheduleTrigger'. Microsoft.Azure.WebJobs.Host: GenericArguments[0], 'MyScheduler.Schedule', on 'Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement]' violates the constraint of type 'TElement'. mscorlib: GenericArguments[0], 'MyScheduler.Schedule', on 'Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement]' violates the constraint of type parameter 'TElement'.
Azure 函数代码如下所示:
using System;
using System.Linq;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage.Table;
namespace MyScheduler
{
public class ScheduleTrigger
{
public static void Run(TimerInfo scheduleTimer, Queryable<Schedule> schedulesTable, ICollector<Schedule> scheduleQueueItem, TraceWriter log)
{
log.Info($"Start processing at: {DateTime.Now}.");
// processing code here...
log.Info($"Finished processing at: {DateTime.Now}.");
}
}
public class Schedule : TableEntity
{
public string Name { get; set; }
public DateTime LastRunAt { get; set; }
public bool Active { get; set; }
public string Endpoint { get; set; }
}
}
“function.json”文件如下所示:
{
"scriptFile": "..\bin\MyScheduler.dll",
"entryPoint": "MyScheduler.ScheduleTrigger.Run",
"bindings": [
{
"name": "scheduleTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 * * * * *"
},
{
"type": "table",
"name": "schedulesTable",
"tableName": "schedules",
"partitionKey": "Schedules",
"connection": "AzureWebJobsStorage",
"direction": "in"
},
{
"type": "queue",
"name": "scheduleQueueItem",
"queueName": "schedulesqueue",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
],
"disabled": true
}
几件事:
- 确保您引用的是 Azure 存储 SDK 7.2.1 或更低版本(最好是 7.2.1)
- 预编译函数的最新模型,完整 tooling/Visual Studio 集成,记录在案 here。请考虑切换到那个。
我正在尝试使用“将 .NET class 库发布为函数应用程序”将 Azure 函数应用程序转换为预编译版本 blog post 来自 Donna Malayeri。
我使用的计时器触发器有一个使用类型化对象的 StorageTable 输入绑定。该对象继承自“TableEntity”。虽然门户中的版本没有任何问题,但我的预编译版本抛出以下错误:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ScheduleTrigger'. Microsoft.Azure.WebJobs.Host: GenericArguments[0], 'MyScheduler.Schedule', on 'Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement]' violates the constraint of type 'TElement'. mscorlib: GenericArguments[0], 'MyScheduler.Schedule', on 'Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToIQueryableConverter`1[TElement]' violates the constraint of type parameter 'TElement'.
Azure 函数代码如下所示:
using System;
using System.Linq;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage.Table;
namespace MyScheduler
{
public class ScheduleTrigger
{
public static void Run(TimerInfo scheduleTimer, Queryable<Schedule> schedulesTable, ICollector<Schedule> scheduleQueueItem, TraceWriter log)
{
log.Info($"Start processing at: {DateTime.Now}.");
// processing code here...
log.Info($"Finished processing at: {DateTime.Now}.");
}
}
public class Schedule : TableEntity
{
public string Name { get; set; }
public DateTime LastRunAt { get; set; }
public bool Active { get; set; }
public string Endpoint { get; set; }
}
}
“function.json”文件如下所示:
{
"scriptFile": "..\bin\MyScheduler.dll",
"entryPoint": "MyScheduler.ScheduleTrigger.Run",
"bindings": [
{
"name": "scheduleTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 * * * * *"
},
{
"type": "table",
"name": "schedulesTable",
"tableName": "schedules",
"partitionKey": "Schedules",
"connection": "AzureWebJobsStorage",
"direction": "in"
},
{
"type": "queue",
"name": "scheduleQueueItem",
"queueName": "schedulesqueue",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
],
"disabled": true
}
几件事:
- 确保您引用的是 Azure 存储 SDK 7.2.1 或更低版本(最好是 7.2.1)
- 预编译函数的最新模型,完整 tooling/Visual Studio 集成,记录在案 here。请考虑切换到那个。