.net 8 + source generated log messages causes build error: error CS0757: A partial method may not have multiple implementing declarations
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
Logging source generators are failing with the following error:
_error **CS0757**: A partial method may not have multiple implementing declarations_
This error occurs when I create a multi-targeted project (.net 8, 9 and 10), that references a multi-targeted nuget package, which uses .net 9 framework references.
```
Restore complete (0,7s)
info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
LoggingTest net8.0 failed with 1 error(s) (1,6s)
C:\Users\erwin\source\repos\LoggingTest\LoggingTest\obj\Debug\net8.0\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(44,36): error CS0757: A partial method may not have multiple implementing declarations
LoggingTest net9.0 succeeded (2,0s) → LoggingTest\bin\Debug\net9.0\LoggingTest.dll
LoggingTest net10.0 succeeded (2,0s) → LoggingTest\bin\Debug\net10.0\LoggingTest.dll
```
The .net 9 build works fine, but the .net 8 and 10 build fail with above error.
My scenario is as follows:
I'm building a multi-targeted library. It needs to target .net 8, 9 and now also 10. I'm referencing a different library (
Duende.AccessTokenManagement.OpenIdConnect, Version="4.0.0-rc.2). This library supports .net 8 and .net 9, but needs to also use hybrid cache (which is only available in .net 9). So, even though it's a .net 8 library, it references .net 9 assemblies.
### To Reproduce
Here's a gist to reproduce it:
https://gist.github.com/Erwinvandervalk/7c6f0177f69c778185cb2ab18e6c079f
Basically:
``` xml
net8.0;net9.0;net10.0
enable
enable
8.0.1
****
```
A multi-targeted assembly, that targets another multi-targeting assembly
```csharp
internal static partial class LogMessages
{
[LoggerMessage(
Message = "Persisting authentication state")]
public static partial void PersistingAuthenticationState(this ILogger logger, LogLevel logLevel);
}
```
### Further technical details
I've tested this with preview 6 and 7.
.NET SDK:
Version: 10.0.100-preview.7.25380.108
Commit: 30000d883e
Workload version: 10.0.100-manifests.8bb6be96
MSBuild version: 17.15.0-preview-25380-108+30000d883
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.
Host:
Version: 10.0.0-preview.7.25380.108
Architecture: x64
Commit: 30000d883e
.NET SDKs installed:
8.0.413 [C:\Program Files\dotnet\sdk]
9.0.109 [C:\Program Files\dotnet\sdk]
9.0.304 [C:\Program Files\dotnet\sdk]
10.0.100-preview.7.25380.108 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-preview.7.25380.108 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-preview.7.25380.108 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-preview.7.25380.108 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
C:\Users\erwin\source\repos\LoggingTest\global.json
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.