Azure / Azure-Functions

1.11k stars 195 forks source link

Exception while using Cosmos Table Api with function v1.0 #1243

Open pranav1509 opened 5 years ago

pranav1509 commented 5 years ago

We are getting below error while using cosmos table api with azure function v1.0

Exception: Method not found: 'Void Microsoft.Azure.Documents.Client.DocumentClient..ctor(System.Uri, System.String, Newtonsoft.Json.JsonSerializerSettings, Microsoft.Azure.Documents.Client.ConnectionPolicy, System.Nullable`1)'.

StackTrace: at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionExecutor.<>c__DisplayClass19_02.<<ExecuteQuerySegmentedInternalAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionRetryPolicy.<ExecuteUnderRetryPolicy>d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at TestFunction.CosmosStorageHelper.<RetrieveFromStorageAsync>d__01.MoveNext()

This makes cosmos db unusable with azure function v1.0.

ColbyTresness commented 5 years ago

@brettsam for cosmos integration

brettsam commented 5 years ago

What version of the Cosmos nugets are you using? My guess is that this is b/c v1 is using an older nuget package built-in.

@ealsur as FYI.

ealsur commented 5 years ago

What are the packages being referenced in the project? This sounds like an issue with version mismatch.

If the user is using Microsoft.Azure.WebJobs.Extensions.DocumentDB because they are using some Cosmos DB binding / trigger, then that limits them to SDK 1.13.2. This stack trace doesn't seem to be coming from the binding / trigger, so if they want to use a higher SDK, they could reference the SDK directly and remove the Microsoft.Azure.WebJobs.Extensions.DocumentDB package reference.

pranav1509 commented 5 years ago

@ealsur We are using Microsoft.Azure.Cosmos.Table nuget and we are creating our own storageAccount client. We are not using bindings as such.

I have tried using several nuget versions starting from latest to the first one , also attempted to use Microsoft.Azure.cosmosDb.table nuget in oder to verify if that works. None of the Nuget worked here.

ealsur commented 5 years ago

Could you list all the packages and version? I believe Microsoft.Azure.Cosmos.Table 1.0.1 has a dependency on Newtonsoft.Json >= 10.

Azure Functions V1 has 9.0.0.1 - that can't be worked around, right @brettsam ?

FinVamp1 commented 5 years ago

Sample from Pranav at https://github.com/FinVamp1/CosmosTableDemo

<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.1" />

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />

<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
ealsur commented 5 years ago

The Microsoft.NET.Sdk.Functions package for V1 has a hard dependency on Newtonsoft.Json 9.0.1

image

See https://github.com/Azure/azure-functions-host/wiki/Assembly-Resolution-in-Azure-Functions#what-are-the-challenges-when-running-on-azure-functions

pranav1509 commented 5 years ago

@ealsur We use runtime assembly binding to resolve such issues , i did the same for newtonsoft.json assembly as well. It stopped giving me version number mismatch but then i got exception while running my code. You may refer to code which @FinVamp1 has shared.

Also, are you suggesting that it is not at all possible to use Microsoft.Azure.Cosmos.Table Nuget with functions v1.0?

ealsur commented 5 years ago

All that I'm saying is that there is a Method Not Found on runtime, that means that binding redirects are not actually redirecting references. The Method that is missing has one of the Newtonsoft.Json classes in the signature. That would mean that, on runtime, the expected signature with the class version, is not found.

Based on the Nuget packages requirements on the Microsoft.Azure.Cosmos.Table package, and Newtonsoft.Json being locked on 9.0.1 on Functions V1, my guess is that this is not possible. I don't even know how Nuget let you do a restore on that project since it breaks the Microsoft.NET.Sdk.Functions dependencies. image