dotnet / dotnet/wpf

[LoggerMessageAttribute] generates CS0757 and CS0102 when combined with XAML and certain NuGet package references.

Open
#9,589 15 comments 0 reactions 0 assignees View on GitHub
:beetle: bug blocking Bug Investigate regression
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

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

```






```

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:

```




```

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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.