dotnet / dotnet/extensions

Compile error when using `Microsoft.Extensions.Telemetry.Abstractions` in `.NETStandard2.1` projects

Open
#6,733 3 comments 0 reactions 0 assignees 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

Try to use the same code, multi-targeting `.NET 6` and `.NETStandard2.1`, build failure on `netstandard`.

Image

### Reproduction Steps

Here's the source code for a repro:

```csharp
using Microsoft.Extensions.Logging;

struct TestObject
{
public int Id { get; set; }
}

internal static partial class TestObjExtensions
{
[LoggerMessage(Level = LogLevel.Information, Message = "Logging TestObject with Id")]
public static partial void LogTestObject(this ILogger logger, [LogProperties(OmitReferenceName = true)] in TestObject testObject);
}
```

Project file, multi-targeting for 2 Fx:

```xml


Exe
10.0
net6.0;netstandard2.1
enable
enable



```

### Expected behavior

`Microsoft.Extensions.Telemetry.Abstractions` supports `.NETStandard 2.1` like on NuGet page:

Image

### Actual behavior

Build warning + error:

```shell
LearnLoggingComplexObjects netstandard2.1 failed with 1 error(s) and 1 warning(s) (0.2s)
C:\Demo\LearnLoggingComplexObjects\TestObj.cs(11,121): warning SYSLIB1015: Argument 'testObject' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1015)
C:\Demo\LearnLoggingComplexObjects\obj\Debug\netstandard2.1\Microsoft.Gen.Logging\Microsoft.Gen.Logging.LoggingGenerator\Logging.g.cs(11,32): error CS0757: A partial method may not have multiple implementing declarations
LearnLoggingComplexObjects net6.0 succeeded (0.8s) → bin\Debug\net6.0\LearnLoggingComplexObjects.dll
```

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

_No response_

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