Azure-Functions
Azure-Functions copied to clipboard
ImplicitUsings enable gives ambiguous reference between 'System.Threading.ExecutionContext' and 'Microsoft.Azure.WebJobs.ExecutionContext'
When binding to ExecutionContext and if ImplicitUsings is enabled, is there guideance on how this could be done without using a fully qualified reference to Microsoft.Azure.WebJobs.ExecutionContext? Whilst not strictly speaking a bug, and ImplicitUsings is not activated in the project templates, if would be nice if this name ambigiuty didn't lead people to disable implicit usings for Functions eg. by having new derived type FunctionExecutionContext. Or for this to be mentioned in documentation.
Error CS0104 'ExecutionContext' is an ambiguous reference between 'System.Threading.ExecutionContext' and 'Microsoft.Azure.WebJobs.ExecutionContext'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<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>
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ExecutionContext context)
{
return new OkObjectResult(context.InvocationId);
}
}
}
Hi @andybooth, Thank you for your feedback! We will investigate this further and update you with the findings.
Flagging this issue as a feature enhancement request so that team can make a change on this.
I appreciate this issue might be aged & newer language capabilities available 9 months on, but today:
-
You can add an alias using to the Function.cs file, eg:
using ExecutionContext = Microsoft.Azure.WebJobs.ExecutionContext;
-
You can add a global alias (obviously the choice is set for all project .cs files) as follows:
-
to the top of a single .cs file in the project, eg:
global using ExecutionContext = Microsoft.Azure.WebJobs.ExecutionContext;
-
to an ItemGroup in the .csproj file, eg:
<Using Include="Microsoft.Azure.WebJobs.ExecutionContext" Alias="ExecutionContext" />
-