c# - 绑定(bind)中的Azure函数表存储违反了类型参数 'TElement'的约束

标签 c# azure azure-functions azure-table-storage

我正在从我的 Azure 函数中的表存储中读取数据。我已经在表存储绑定(bind)中创建了 HttpTrigger 函数。项目正在使用存储包:

"WindowsAzure.Storage": "8.0.0"

和绑定(bind):

{
  "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+TableToIQueryableConverter1[TElement]' violates the constraint of type parameter 'TElement'.

任何人都可以帮助我解决这个问题或遇到同样的错误吗?

最佳答案

错误消息看起来有点奇怪,但请尝试从 project.json 文件中删除 WindowsAzure.Storage 引用。该包由运行时自动引用,如果您显式包含它,则会因版本不匹配而出现各种错误。

我从您的代码创建了一个干净的 Azure 函数,没有包引用,它编译并运行得很好。尝试同样的方法。

关于c# - 绑定(bind)中的Azure函数表存储违反了类型参数 'TElement'的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42763467/

相关文章:

asp.net-mvc-4 - 在 Azure 中与 MVC 项目一起运行 WebApi

node.js - 以编程方式在 Sharepoint 中编辑 Excel 文件

Azure Key Vault 保护证书

azure - 如何从 vs code 发布 azure 函数?

c# - .NET Core Web应用程序启动类中的app.UseMigrationsEndPoint做什么

C# Linq 打印的值与 Debug模式下显示的值不同

Azure 数据工厂 - 参数插值

c# - 在 Azure Function 中按顺序处理服务总线消息(无并发调用)

c# - 如何在 C# 中从 ECDsa 获取公钥

c# - 如何在 C# 程序和 Node.js 程序之间使用 Msgpack?