Azure 函数中的奇怪冲突

Odd Conflict in Azure Function

我在使用 Visual Studio 工具进行函数输入绑定时遇到了一个奇怪的问题。我创建了一个简单的函数,它有一个 http 触发器和一个用于 table 存储的输入绑定:

  [FunctionName("Scaling")]
    public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "HttpTriggerCSharp/name/{name}")]HttpRequestMessage req, string name, [Table("scalingdatawesteurope", Connection = "scalingdataStorage")]CloudTable scalingDataTable, TraceWriter log)
    {
        log.Info("C# HTTP trigger function processed a request.");
        var customerScaleData = GetScaleData(name, scalingDataTable);
        log.Info("Sub:" + customerScaleData.Subscription);
        // Fetching the name from the path parameter in the request URL
        return req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
    }

这工作正常,并检索到我想要的数据。但是,我现在想做的是使用这些数据 运行 使用 ARM API 针对其他 Azure 资源进行一些操作。因此,我使用 Nuget 导入 Microsoft.Azure.Management.Fluent 包以允许我执行此操作。一旦我导入这个包并将其添加为依赖项,我的函数就开始失败。如果我删除它,一切都会重新开始。

[23/10/2017 12:23:14] A ScriptHost error has occurred
[23/10/2017 12:23:14] Microsoft.Azure.WebJobs.Host: Error indexing method 'Scaling.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
[23/10/2017 12:23:14] Error indexing method 'Scaling.Run'
[23/10/2017 12:23:14] Microsoft.Azure.WebJobs.Host: Error indexing method 'Scaling.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
[23/10/2017 12:23:14] 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.).
[23/10/2017 12:23:14] Job host started
[23/10/2017 12:23:14] The following 1 functions are in error:
[23/10/2017 12:23:14] Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'Scaling.Run'. Microsoft.Azure.WebJobs.Host: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
[23/10/2017 12:23:14]
[23/10/2017 12:23:14]
[23/10/2017 12:23:14] Host lock lease acquired by instance ID '000000000000000000000000F195573C'.
Debugger listening on [::]:5858

这里似乎存在某种冲突,但我正在努力寻找或修复它。

Microsoft.Azure.Management.ContainerInstance.Fluent 依赖于版本 8.1.4WindowsAzure.Storage,而 Functions 运行时使用 7.2.1.

您可以在 this github issue 中阅读有关 Azure Functions 版本冲突问题的更多信息。

但最简单的解决方法可能是不使用保护伞 Microsoft.Azure.Management.Fluent(因此 ContainerInstance.Fluent),而是仅引用您明确需要的子库。

更新:

如您所述,您可能无法使用子库,因为 Authenticate 来自父库的调用。

到目前为止我发现的唯一解决方法是切换到 2.0 运行时的 beta 版本,其中使用 WindowsAzure.Storage8.x 版本。