dotnet / dotnet/extensions

Compilation error when using Microsoft.Extensions.Telemetry.Abstractions with multiple TFMs

Open
#7,061 0 comments 4 reactions 1 assignee Assigned to @Copilot View on GitHub
area-telemetry bug untriaged
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Description

Compilation error when using multi targeting such as .NET 10 and NET 9.0 or NET 8.0 or both of them.

Image

### Reproduction Steps

csproj file:
```


net9.0;net10.0
enable
enable
Exe





```

Program.cs:
```csharp
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Logging;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();
app.MapGet("/index", () =>
{
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = loggerFactory.CreateLogger("repro");

Log.Hello(logger, "hi");
});

app.Run();

internal static partial class Log
{
[LoggerMessage(LogLevel.Information, "Hello {Name}.")]
internal static partial void Hello(ILogger logger, string name);
}

```

### Expected behavior

Microsoft.Extensions.Logging.Abstractions does not kick in, code compiles and works correctly

### Actual behavior

Compilation error CS0757 A partial method may not have multiple implementing declarations

### Regression?

_No response_

### Known Workarounds

Add this to csproj file:
```





```

### Configuration

.NET 10 and multi targeting build with previous .NET such as 8.0 and/or 9.0

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