【问题标题】:Azure Function 2 - missing a using directive or an assembly reference?Azure Function 2 - 缺少 using 指令或程序集引用?
【发布时间】:2022-02-23 23:18:00
【问题描述】:

我使用 Visual Studio 2017 创建了我的 Azure Function v2。

我创建了一个新的队列触发器函数。

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace Functions
{
    public static class queue
    {
        [FunctionName("queue")]
        public static void Run([QueueTrigger("myqueue-items", Connection = "test")]string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }
    }
}

但是找不到QueueTrigger的程序集

Error   CS0246  The type or namespace name 'QueueTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error   CS0246  The type or namespace name 'QueueTrigger' could not be found (are you missing a using directive or an assembly reference?)
Error   CS0246  The type or namespace name 'Connection' could not be found (are you missing a using directive or an assembly reference?)

【问题讨论】:

  • 我建议重新检查文档以确保您正确配置了所有内容。 docs.microsoft.com/en-us/azure/azure-functions/…
  • Visual Studio 2017 存在一个错误。当我使用空白选项创建新的 Azure 函数项目时。发生此错误。但是如果我使用一些模板创建,这个错误就不会发生。
  • 遗憾的是,截至 2020 年 9 月 21 日的最新 VS 2019 更新,此问题仍未修复。据我了解,这些模板现在带有核心 VS 更新,而不是单独的工具/扩展更新,除非有人知道不同?只是想确定在哪里报告。
  • 在这里安装这些包救了我stackoverflow.com/a/61493781/5937760

标签: azure-functions .net-assembly


【解决方案1】:

正如 Nkosi 所说,您可以转到 Azure Queue storage bindings for Azure Functions 以检查您是否配置了绑定扩展。

为了您的信息,我认为您需要安装Microsoft.Azure.WebJobs.Extensions.Storage NuGet 包,版本 3.x。然后一切都会好起来的。

【讨论】:

    【解决方案2】:

    我使用 cli 工具在 Visual Studio 代码中创建了一个队列触发函数。它在 host.json 文件中创建了 2.0 版的 azure 函数。当我运行该函数时,我得到了同样的错误。我可以通过在 .csproj 文件中添加以下行来解决此问题。

    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
    

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多