Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use premium tables in Azure Functions #2026

Closed
Gorthog opened this issue Oct 12, 2017 · 8 comments
Closed

Cannot use premium tables in Azure Functions #2026

Gorthog opened this issue Oct 12, 2017 · 8 comments

Comments

@Gorthog
Copy link

Gorthog commented Oct 12, 2017

I'm trying to use premium tables but I get a 400 error code when I execute retrieve operation. After some investigation it looks like even though the premium tables nuget is referenced in csproj, what actually gets loaded by the run time is the standard version of WindowsAzure.Storage

Repro steps

  1. Add nuget "WindowsAzure.Storage-PremiumTable" version 0.1.0-preview to csproj
  2. Place the following code in Azure Function project
var connectionString = ConfigurationManager.AppSettings["PREMIUM_CONNECTION_STRING"];
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(name);
TableOperation retrieveOperation = TableOperation.Retrieve<SomeEntity>(paritionKey, rowKey);

string assembly = $"{table.GetType().Assembly.FullName}";

TableResult retrievedResult = table.Execute(retrieveOperation);
  1. Debug using VS 2017.3.5

Expected behavior

"assembly" should be WindowsAzure.Storage-PremiumTable

Actual behavior

"assembly" is Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

@paulbatum paulbatum added this to the Active Questions milestone Oct 25, 2017
@paulbatum
Copy link
Member

What using statements do you have?

@Gorthog
Copy link
Author

Gorthog commented Oct 26, 2017

using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using System.Configuration;
using Microsoft.WindowsAzure.Storage.Table;

Same as I've seen in example from docs: https://github.com/Azure-Samples/azure-cosmos-db-table-dotnet-getting-started/blob/master/PremiumTableGetStarted/Program.cs

Here is my csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net47</TargetFramework>
  </PropertyGroup>
  <ItemGroup>    
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.2" />    
    <PackageReference Include="WindowsAzure.Storage-PremiumTable" Version="0.1.0-preview" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Configuration" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

@paulbatum
Copy link
Member

So i tried this, and there doesn't seem to be anything functions specific about this behavior. I took the same code, ran it into a console application and it does the same thing:

Microsoft.WindowsAzure.Storage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Furthermore I looked inside the nuget you're referencing, and it does not contain an assembly by the name you expected. The assembly is very clearly called Microsoft.WindowsAzure.Storage:

image

@Gorthog
Copy link
Author

Gorthog commented Nov 4, 2017

Ok, my mistake about the assembly name, but the fact remain is that it's not working - I receive 400 error code.

I think the reason is that the wrong assembly is loaded - look at the version, it's 7.2.1.0 in Azure Function but 1.0.0 in console app.

Please reopen.

@paulbatum paulbatum reopened this Nov 5, 2017
@paulbatum
Copy link
Member

I suspect this is related to assembly binding redirects. I don't really understand what is going on with this premium tables library - it seems to mimic the azure storage library. The version shows as 1.0.0.0 but the assembly name and public key token are the same. Since Azure Functions has a binding redirect rule that applies to any version of azure storage older than 7.2.1.0, the rule is applied here and so the version of Microsoft.WIndowsAzure.Storage.dll that is included in this NuGet is not loaded.

You can see this happening with the following code:

CloudTable table = tableClient.GetTableReference("asdf");
var t = table.GetType();
string assembly = $"{t.Assembly.Location} {t.Assembly}";
log.Info(assembly);     

In a console app:
C:\Users\pbatum\source\repos\PremiumTables\ConsoleApp1\bin\Debug\Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

In a function app:

11/7/2017 6:38:00 PM] C:\Users\pbatum\AppData\Local\Azure.Functions.Cli\1.0.4\Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage, Version=7.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

So if I'm correct, this is an unfortunate side effect of the combination of how azure functions handles assembly binding redirects and how this library is authored.

@Gorthog
Copy link
Author

Gorthog commented Nov 13, 2017

So what is the next step toward resolution?
I do believe I'm not the only guy interested in using Azure Functions with Premium Tables.

@paulbatum
Copy link
Member

Honestly I'm not sure. I've reached out to a contact I have on the CosmosDB team to see if they have any ideas.

@Gorthog
Copy link
Author

Gorthog commented Nov 16, 2017

This looks like a duplicate of #1751 So i'm closing it

@Gorthog Gorthog closed this as completed Nov 16, 2017
@ghost ghost locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants