2
votes

I am working on reading data from Table Storage in my Azure Function. I have created HttpTrigger function with in Table Storage binding. Project is using storage package:

"WindowsAzure.Storage": "8.0.0"

and binding:

{
  "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
}

Having code generated by template I have added new in parameter:

#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;  }
}

During save and run process I am getting compile error:

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'.

Can anyone help me with this or meet same error?

1

1 Answers

5
votes

The error message looks a bit weird, but try removing WindowsAzure.Storage reference from project.json file. This package is referenced automatically by the runtime, and if you include it explicitly you get all kinds of errors due to version mismatch.

I created a clean Azure Function from your code without the package reference and it compiled and worked just fine. Try the same.