Azure 函数 Table 绑定中的存储违反了类型参数的约束 'TElement'
Azure Function Table Storage in binding violates the constraint of type parameter 'TElement'
我正在从我的 Azure 函数中的 Table 存储中读取数据。我在 Table 存储绑定中创建了 HttpTrigger 函数。项目正在使用存储包:
"WindowsAzure.Storage": "8.0.0"
和绑定:
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "metadataTable",
"type": "table",
"direction": "in",
"tableName": "metadata",
"connection": "StorageConnectionString",
"partitionkey": "some_partition_key"
}
],
"disabled": false
}
使用模板生成的代码,我在参数中添加了新的:
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req,
IQueryable<MetadataTable> metadataTable, TraceWriter log)
{
.....
}
public class MetadataTable: TableEntity
{
public MetadataTable():base() { }
public MetadataTable(string partitionkey, string rowkey):base(partitionkey,rowkey) {}
public string Data { get; set; }
}
在保存和 运行 过程中出现编译错误:
Microsoft.Azure.WebJobs.Host: Error indexing method
'Functions.HttpTriggerCSharp1'. Microsoft.Azure.WebJobs.Host:
GenericArguments[0], 'Submission#0+MetadataTable', on
'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToIQueryableConverter1[TElement]'
violates the constraint of type 'TElement'. mscorlib:
GenericArguments[0], 'Submission#0+MetadataTable', on
'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToIQueryableConverter
1[TElement]'
violates the constraint of type parameter 'TElement'.
谁能帮我解决这个问题或遇到同样的错误?
错误消息看起来有点奇怪,但请尝试从 project.json
文件中删除 WindowsAzure.Storage
引用。此包由运行时自动引用,如果您显式包含它,则会因版本不匹配而出现各种错误。
我从你的代码创建了一个干净的 Azure Functions,没有包引用,它编译并工作得很好。试试看。
我正在从我的 Azure 函数中的 Table 存储中读取数据。我在 Table 存储绑定中创建了 HttpTrigger 函数。项目正在使用存储包:
"WindowsAzure.Storage": "8.0.0"
和绑定:
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "metadataTable",
"type": "table",
"direction": "in",
"tableName": "metadata",
"connection": "StorageConnectionString",
"partitionkey": "some_partition_key"
}
],
"disabled": false
}
使用模板生成的代码,我在参数中添加了新的:
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req,
IQueryable<MetadataTable> metadataTable, TraceWriter log)
{
.....
}
public class MetadataTable: TableEntity
{
public MetadataTable():base() { }
public MetadataTable(string partitionkey, string rowkey):base(partitionkey,rowkey) {}
public string Data { get; set; }
}
在保存和 运行 过程中出现编译错误:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTriggerCSharp1'. Microsoft.Azure.WebJobs.Host: GenericArguments[0], 'Submission#0+MetadataTable', on 'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToIQueryableConverter
1[TElement]' violates the constraint of type 'TElement'. mscorlib: GenericArguments[0], 'Submission#0+MetadataTable', on 'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToIQueryableConverter
1[TElement]' violates the constraint of type parameter 'TElement'.
谁能帮我解决这个问题或遇到同样的错误?
错误消息看起来有点奇怪,但请尝试从 project.json
文件中删除 WindowsAzure.Storage
引用。此包由运行时自动引用,如果您显式包含它,则会因版本不匹配而出现各种错误。
我从你的代码创建了一个干净的 Azure Functions,没有包引用,它编译并工作得很好。试试看。