azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Unexpected build warning CS0436

Open danieladolfsson-work opened this issue 2 years ago • 6 comments

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:

  1. Create a new console app project (ConsoleApp1)
  2. Create a new unit test project (TestProject1)
  3. Add a project reference from TestProject1 to ConsoleApp1
  4. Add [assembly: InternalsVisibleTo("TestProject1")] to Program.cs
  5. Add NuGet package Microsoft.Azure.Functions.Worker.Sdk 1.7.0 to ConsoleApp1
  6. Add NuGet package Microsoft.Azure.Functions.Worker.Extensions.OpenApi 1.5.1 to ConsoleApp1
  7. 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 \FunctionApp1\TestProject1\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.ExtensionStartupRunnerGenerator\WorkerExtensionStartupCodeExecutor.g.cs

danieladolfsson-work avatar Feb 09 '23 15:02 danieladolfsson-work

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.

JoasE avatar Apr 19 '23 08:04 JoasE

Got it aswell

wkoeter avatar Jul 18 '23 13:07 wkoeter

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

nootn avatar Jul 19 '23 23:07 nootn

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>

nootn avatar Jul 19 '23 23:07 nootn

I have changed version of Microsoft.Azure.Functions.Worker.Sdk from 1.16.3 to 1.16.2. Rebuild and the error is gone

m-malik15 avatar Dec 07 '23 12:12 m-malik15

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

BrettBailey avatar Dec 07 '23 15:12 BrettBailey