azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Unexpected build warning CS0436
Describe the issue Unexpected build warning (CS0436) when using Microsoft.Azure.Functions.Worker.Sdk and project reference in combination with InternalsVisibleToAttribute.
To Reproduce Steps to reproduce the behavior:
- Create a new console app project (ConsoleApp1)
- Create a new unit test project (TestProject1)
- Add a project reference from TestProject1 to ConsoleApp1
- Add [assembly: InternalsVisibleTo("TestProject1")] to Program.cs
- Add NuGet package Microsoft.Azure.Functions.Worker.Sdk 1.7.0 to ConsoleApp1
- Add NuGet package Microsoft.Azure.Functions.Worker.Extensions.OpenApi 1.5.1 to ConsoleApp1
- Rebuild -> Build warning CS0436
Expected behavior No warning on build.
Environment
- TargetFramework: net6.0
Additional context The problem is that two identical classes (one per project) are generated by Microsoft.Azure.Functions.Worker.Sdk.Generator, WorkerExtensionStartupCodeExecutor.g.cs.
// <auto-generated/>
using System;
using Microsoft.Azure.Functions.Worker.Core;
[assembly: WorkerExtensionStartupCodeExecutorInfo(typeof(Microsoft.Azure.Functions.Worker.WorkerExtensionStartupCodeExecutor))]
namespace Microsoft.Azure.Functions.Worker
{
internal class WorkerExtensionStartupCodeExecutor : WorkerExtensionStartup
{
public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
{
try
{
new Microsoft.Azure.Functions.Worker.Extensions.OpenApi.OpenApiWorkerStartup().Configure(applicationBuilder);
}
catch (Exception ex)
{
Console.Error.WriteLine("Error calling Configure on Microsoft.Azure.Functions.Worker.Extensions.OpenApi.OpenApiWorkerStartup instance."+ex.ToString());
}
}
}
}
Warning message: Warning CS0436 The type 'WorkerExtensionStartupCodeExecutor' in 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs' conflicts with the imported type 'WorkerExtensionStartupCodeExecutor' in 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs'. TestProject1
I've got the same issue. I don't think it is causing any problems in production, but the warning does keep popping up in our quality gate check on PR's.
Got it aswell
I get this but I think because I have Warnings as Errors I actually can't build my solution! Is it possible for the code to not be generated in the project that is not referencing this package directly? I think that woud be an ideal fix. I.e. in the scenario above, the code would get generated in "ConsoleApp1", but would not get generated in "TestProject1".
Ah, I found a workaround for now! If I ignore the compiler warning in the UnitTest1 project by adding <NoWarn>0436</NoWarn>
, then at least I can build again:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>0436</NoWarn>
</PropertyGroup>
I have changed version of Microsoft.Azure.Functions.Worker.Sdk from 1.16.3 to 1.16.2. Rebuild and the error is gone
Similar issue here, I had full compile errors in the generated code for WorkerExtensionStartupCodeExecutorInfo.
Fixed with downgrade of Microsoft.Azure.Functions.Worker.Sdk from 1.16.3 to 1.16.2. thanks @m-malik15