user17758597
user17758597

Reputation:

The type or namespace name 'Queue' could not be found in Azure Functions Http Trigger C#

I have created Azure Functions Http Trigger (C#) through VS Code.

I'm getting few namespace errors which I tried to resolve by installing few packages like Azure WebJobs, Azure WebJobs Extensions, System Component DataAnnotation package but the error is not going.

The error is in this image - Click on Me!

Error in Text Format: For this line:

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

Error:

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)

For this line:

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

Error:

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)

Code is available in https://github.com/licjapodaca/pluralsightfuncs/blob/master/OnPaymentReceived.cs

My .csproj code:

<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>

Upvotes: 1

Views: 2766

Answers (1)

AjayKumarGhose
AjayKumarGhose

Reputation: 4883

One of the workaround could be solve the above issue, I have tested in my environment with your code to remove those errors and its working fine as expected .

As suggested by @Chetan in comment found that, We need to Install Nuget package Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" and it will remove the above two errors.

.csproj file:

<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>

Here are the screenshots for your reference: enter image description here

enter image description here

For more information please refer the below links: MS DOC: CREATE AZURE FUNCTION USING VSCODE & Azure Table storage bindings for Azure Functions

Upvotes: 3

Related Questions