C# 绑定中的Azure函数表存储违反了类型参数';远程医疗';
我正在Azure函数中从表存储读取数据。我已经用表内存储绑定创建了HttpTrigger函数。项目正在使用存储包:C# 绑定中的Azure函数表存储违反了类型参数';远程医疗';,c#,azure,azure-functions,azure-table-storage,C#,Azure,Azure Functions,Azure Table Storage,我正在Azure函数中从表存储读取数据。我已经用表内存储绑定创建了HttpTrigger函数。项目正在使用存储包: "WindowsAzure.Storage": "8.0.0" 和约束: { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in" }, { "name
"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; }
}
#r“Microsoft.WindowsAzure.Storage”
使用制度;
Net系统;
使用Microsoft.WindowsAzure.Storage.Table;
使用Microsoft.WindowsAzure.Storage;
公共静态异步任务运行(HttpRequestMessage req,
IQueryable元数据表,TraceWriter日志)
{
.....
}
公共类MetadataTable:TableEntity
{
公共MetadataTable():base(){}
公共元数据表(string partitionkey,string rowkey):基(partitionkey,rowkey){}
公共字符串数据{get;set;}
}
在保存和运行过程中,我遇到编译错误:
Microsoft.Azure.WebJobs.Host:索引方法出错
'Functions.HttpTriggerCSharp1'。Microsoft.Azure.WebJobs.Host:
一般参数[0],“提交#0+元数据表”,关于
'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToQueryableConverter1[TElement]'
违反类型“TElement”的约束。mscorlib:
一般参数[0],“提交#0+元数据表”,关于
'Microsoft.Azure.WebJobs.Host.Tables.TableAttributeBindingProvider+TableToQueryableConverter
1[TElement]'
违反类型参数“TElement”的约束
有谁能帮我解决这个问题或遇到同样的错误吗?错误消息看起来有点奇怪,但请尝试从
project.json
文件中删除WindowsAzure.Storage
引用。运行时会自动引用此包,如果显式包含它,则会由于版本不匹配而出现各种错误
我从您的代码中创建了一个干净的Azure函数,没有包引用,它编译后运行良好。试试同样的。谢谢你,米哈伊尔。您知道如何为Azure函数宿主环境(Newtonsoft.Json、Microsoft.WindowsAzure.Storage等)自动添加的程序集设置特定版本吗?不,我不知道这种可能性。我对Visual Studio 2017创建的函数应用程序也有同样的问题,该应用程序没有project.json或对WindowsAzure.Storage的引用。[31/08/2017 12:49:20]运行:Microsoft.Azure.WebJobs.Host:错误索引方法“SearchTrucks.Run”。Microsoft.Azure.WebJobs.Host:Microsoft.Azure.WebJobs.Host.Tables.TableExtension+TableToQueryableConverter“1[TElement]”上的GenericArguments[0]、“NNN.NNN.NNN”违反了“TElement”类型的约束。mscorlib: