8000 [LoggerMessageAttribute] generates CS0757 and CS0102 when combined with XAML and certain NuGet package references. · Issue #9589 · dotnet/wpf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[LoggerMessageAttribute] generates CS0757 and CS0102 when combined with XAML and certain NuGet package references. #9589
Open
@daviddunson

Description

@daviddunson

Description

Build will fail when targeting specific NuGet packages in addition to compiling with a .XAML file. If the .XAML file is removed, or the NuGet package is removed, the build will succeed. It is when .XAML, [LoggerMessage] and specific packages are referenced.

This was discovered while embedding an ASP.NET Core host inside a WPF application. These packages were referenced in a class library that was referenced by the WPF project:

    <PackageReference Include="IdentityServer4" Version="4.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
    <PackageReference Include="System.Linq.Async" Version="6.0.1" />
    <PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />

I was able to reproduce the error by creating a new WPF project and adding a direct reference to one of these packages.

Reproduction Steps

Create a new C# WPF Application targeting .NET 8.

Add the following package references:

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
  </ItemGroup>

Add a class containing a [LoggerMessage] reference:

    public static partial class LoggerExtensions
    {
        [LoggerMessage(LogLevel.Error, "Your message: {Message}")]
        public static partial void SomethingFailed(this ILogger logger, string message);
    }

Try to build the project.

Expected behavior

Build succeeded.

Actual behavior

Build failed.

1>...obj\Debug\net8.0-windows\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(13,36,13,51): error CS0757: A partial method may not have multiple implementing declarations
1>...obj\Debug\net8.0-windows\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(9,151,9,176): error CS0102: The type 'LoggerExtensions' already contains a definition for '__SomethingFailedCallback'

Regression?

Project will build after rolling back to Visual Studio 17.9.

Known Workarounds

Move the members with [LoggerMessageAttribute] to a class library that does not contain a .XAML file and a reference to one of the packages that trigger the failure.

Configuration

Windows Version 11 23H2 (x64)
Visual Studio 17.11 (or 17.10)
.NET SDK 8.0.400

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateRequires further investigation by the WPF team.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0