Skip to content

Instantly share code, notes, and snippets.

@MrMikeFloyd
Last active February 22, 2018 14:35
Show Gist options
  • Save MrMikeFloyd/16d93f0bace0bd1229f6b7767c96569c to your computer and use it in GitHub Desktop.
Save MrMikeFloyd/16d93f0bace0bd1229f6b7767c96569c to your computer and use it in GitHub Desktop.
Minimal C# Azure Function with an inbound table storage binding, resulting in "Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'System.Linq.IQueryable`1[test.TableRow]'". Created on macOS High Sierra with Visual Studio Code 1.19.3 and .NET Core 2.0.5
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xxxxxxx;AccountKey=xxxxxxxxxxxxxx",
"AzureWebJobsDashboard": ""
}
}
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using System.Linq;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Net.Http;
using System.Net;
namespace test
{
public class TableRow : TableEntity
{
public Int32 valueX { get; set; }
public Int32 valueY { get; set; }
public Int32 valueZ { get; set; }
}
public static class read_from_tabstorage
{
[FunctionName("read_from_tabstorage")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
[Table("tabstoragetbl1", "")] IQueryable<TableRow> tRows,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var row = tRows.FirstOrDefault();
if(row != null)
{
log.Info($"Data received: {row.valueX}");
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
@MrMikeFloyd
Copy link
Author

Build output

> Executing task: dotnet build <

Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored using '.NETFramework,Version=v4.6.1'instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
  Restore completed in 25.52 ms for /Users/xxx/dev/test-fkt/test-fkt.csproj.
/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored using '.NETFramework,Version=v4.6.1'instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
  test-fkt -> /Users/xx/dev/vs/vscode/test-fkt/bin/Debug/netstandard2.0/bin/test-fkt.dll
/Users/xxx/.nuget/packages/microsoft.net.sdk.functions/1.0.6/build/netstandard1.0/Microsoft.NET.Sdk.Functions.Build.targets(32,5): warning :  [/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj]

Build succeeded.

/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored using '.NETFramework,Version=v4.6.1'instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored using '.NETFramework,Version=v4.6.1'instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/Users/xxx/.nuget/packages/microsoft.net.sdk.functions/1.0.6/build/netstandard1.0/Microsoft.NET.Sdk.Functions.Build.targets(32,5): warning :  [/Users/xxx/dev/xxx/test-fkt/test-fkt.csproj]
    3 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.35

@MrMikeFloyd
Copy link
Author

Runtime output

Executing with func host start from the target directory.

[02/10/2018 09:15:50] Reading host configuration file '/Users/xxx/dev/xxx/test-fkt/bin/Debug/netstandard2.0/host.json'
[02/10/2018 09:15:50] Host configuration file read:
[02/10/2018 09:15:50] {}
[02/10/2018 09:15:50] Generating 1 job function(s)
[02/10/2018 09:15:50] Starting Host (HostId=xxx-1595519538, Version=2.0.11415.0, ProcessId=1273, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[02/10/2018 09:15:52] A ScriptHost error has occurred
[02/10/2018 09:15:52] Microsoft.Azure.WebJobs.Host: Error indexing method 'read_from_tabstorage.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'System.Linq.IQueryable`1[test.TableRow]'.
[02/10/2018 09:15:52] Error indexing method 'read_from_tabstorage.Run'
[02/10/2018 09:15:52] Microsoft.Azure.WebJobs.Host: Error indexing method 'read_from_tabstorage.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'System.Linq.IQueryable`1[test.TableRow]'.
[02/10/2018 09:15:52] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[02/10/2018 09:15:52] Job host started
[02/10/2018 09:15:52] The following 1 functions are in error:
[02/10/2018 09:15:52] Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'read_from_tabstorage.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'System.Linq.IQueryable`1[test.TableRow]'.
[02/10/2018 09:15:52] 
[02/10/2018 09:15:52] 
Listening on http://localhost:7071/
Hit CTRL-C to exit...

@MrMikeFloyd
Copy link
Author

According to this issue, this is behaviour by design as support for IQueryable was dropped for v2 functions (reference). Therefore, CloudTable remains an option when binding to TableStorage in Azure v2 functions.

@MrMikeFloyd
Copy link
Author

Minimal working example for CloudTables posted here. This seems to be the way to go for v2 functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment