extensions icon indicating copy to clipboard operation
extensions copied to clipboard

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

Open xiaomi7732 opened this issue 4 months ago • 3 comments

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:

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:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <LangVersion>10.0</LangVersion>
    <TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="9.8.0" />
  </ItemGroup>

</Project>

Expected behavior

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

Image

Actual behavior

Build warning + error:

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

xiaomi7732 avatar Aug 20 '25 21:08 xiaomi7732