dotnet / dotnet/wpf

CS0757 & CS0102 Logger source generator error

Open
#10,553 6 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

I have a WPF project, and recently I introduced an ASP FrameworkReference to it, but it resulted in a logger source generator error.

So, I simplified the project as much as possible to reproduce this issue. The code is at [WpfLogger](https://github.com/ali50m/WpfLogger).

### Reproduction Steps

```
git clone git@github.com:ali50m/WpfLogger.git
cd WpfLogger
dotnet build
```

### Expected behavior

Build successfully.

### Actual behavior

Build fail.

```
WpfLogger_gyim0c0w_wpftmp failed with 2 error(s) (2.2s)
C:\Users\liu\source\repos\test\WpfLogger\src\WpfLogger\obj\Debug\net9.0-windows\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(13,36): error CS0757: A partial method may not have multiple implementing declarations
C:\Users\liu\source\repos\test\WpfLogger\src\WpfLogger\obj\Debug\net9.0-windows\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(9,128): error CS0102: The type 'LoggerExtensions' already contains a definition for '__SayHiCallback'

Build failed with 2 error(s) in 3.8s
```

### Regression?

_No response_

### Known Workarounds

Pick any of following can make the build pass.

1. remove Asp frameworkreference from the project [link](https://github.com/ali50m/WpfLogger/blob/9ee8ef2ae30446147c0c500cf117c1f2c256f976/src/WpfLogger/WpfLogger.csproj#L11)
2. downgrade the nuget of "Serilog.Extensions.Logging" to 3.1.0 [link](https://github.com/ali50m/WpfLogger/blob/9ee8ef2ae30446147c0c500cf117c1f2c256f976/src/WpfLogger/WpfLogger.csproj#L15)
3. remove the namespace of this assemble in xaml file [link](https://github.com/ali50m/WpfLogger/blob/9ee8ef2ae30446147c0c500cf117c1f2c256f976/src/WpfLogger/MainWindow.xaml#L5)

### Impact

It will stop me using logger source generator in my WPF project after introducing ASP FrameworkReference.

### Configuration

_No response_

### Other information

dotnet: 9.0.2
windows: 10.0.26100
visual studio: Community Version 17.13.2

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.