【问题标题】:The type or namespace name 'Queue' could not be found in Azure Functions Http Trigger C#在 Azure Functions Http Trigger C# 中找不到类型或命名空间名称“队列”
【发布时间】:2022-01-25 09:19:46
【问题描述】:

我已经通过 VS Code 创建了 Azure Functions Http Trigger (C#)。

我遇到了一些命名空间错误,我试图通过安装几个包(如 Azure WebJobsAzure WebJobs ExtensionsSystem Component DataAnnotation 包)来解决这些错误,但错误并没有发生。

错误出现在这张图片中 - Click on Me!

文本格式错误: 对于这一行:

[Queue("orders")] IAsyncCollector<Order> orderQueue,

错误:

The type or namespace name 'QueueAttribute' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
The type or namespace name 'Queue' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)

对于这一行:

[Table("orders")] IAsyncCollector<Order> orderTable,

错误:

The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)
The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?) [pluralsightfuncs]csharp(CS0246)

代码在https://github.com/licjapodaca/pluralsightfuncs/blob/master/OnPaymentReceived.cs中提供

我的 .csproj 代码:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.30" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

【问题讨论】:

  • 你需要使用Microsoft.Azure.WebJobs.Extensions.Storage.Queues
  • 谢谢@Chetan,有时 Storage 包使用 Queue 和 table 属性,但有时每个属性都要求编写相关的包,如队列等。

标签: c# .net visual-studio-code azure-functions


【解决方案1】:

其中一种解决方法可以解决上述问题,我已经在我的环境中使用您的代码进行了测试,以消除这些错误并按预期正常工作。

正如@Chetan 在comment 中所建议的那样,发现, 我们需要安装Nuget packageMicrosoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5",它将消除上述两个错误。

.csproj文件:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

以下是供您参考的屏幕截图:

更多信息请参考以下链接: MS 医生:CREATE AZURE FUNCTION USING VSCODE & Azure Table storage bindings for Azure Functions

【讨论】:

  • 您好@AjayKumarGhose-MT,因为我已经安装了Microsoft.Azure.WebJobs.Extensions.Storage 软件包,但仍然出现错误。正如 chetan 建议我使用存储的子包,即 queues Microsoft.Azure.WebJobs.Extensions.Storage.Queues 并且它工作得很好。
  • 能否告诉我您安装了哪个版本Microsoft.Azure.WebJobs.Extensions.Storage - v4.0.5
  • 在我尝试安装 Microsoft.Azure.WebJobs.Extensions.Storage.Queues 的情况下,它解决了队列属性的问题,但在表属性中出现了相同的错误。
  • i.imgur.com/0Oy8kes.png - 这是我的 .csproj 文件,您可以在其中查看我安装的软件包及其版本
  • System Component DataAnnotation - 为你的表属性错误安装这个
猜你喜欢
  • 1970-01-01
  • 2013-03-25
  • 2011-06-28
  • 2012-09-27
  • 2021-08-19
  • 1970-01-01
  • 2017-07-12
  • 2011-05-13
相关资源
最近更新 更多