在 Azure Functions Http Trigger C# 中找不到类型或命名空间名称 'Queue'
The type or namespace name 'Queue' could not be found in Azure Functions Http Trigger C#
我已经通过 VS Code 创建了 Azure Functions Http Trigger (C#)。
我遇到了一些命名空间错误,我试图通过安装 Azure WebJobs
、Azure WebJobs Extensions
、System 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>
解决方法之一可以解决上述问题,我已经在我的环境中使用您的代码进行了测试,以消除这些错误并且它按预期正常工作。
正如@Chetan 在 中所建议的那样,发现,
我们需要安装 Nuget package
Microsoft.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>
以下截图供您参考:
更多信息请参考以下链接:
微软文档:CREATE AZURE FUNCTION USING VSCODE & Azure Table storage bindings for Azure Functions
我已经通过 VS Code 创建了 Azure Functions Http Trigger (C#)。
我遇到了一些命名空间错误,我试图通过安装 Azure WebJobs
、Azure WebJobs Extensions
、System 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>
解决方法之一可以解决上述问题,我已经在我的环境中使用您的代码进行了测试,以消除这些错误并且它按预期正常工作。
正如@Chetan 在 Nuget package
Microsoft.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>
以下截图供您参考:
更多信息请参考以下链接: 微软文档:CREATE AZURE FUNCTION USING VSCODE & Azure Table storage bindings for Azure Functions