Skip to content

Possible System.Diagnostics.DiagnosticSource trimming issue #109872

@jamiewinder

Description

@jamiewinder

Description

The System.Diagnostics.DiagnosticSource 9.0.0 package doesn't appear to be trim safe. Specifically the ActivitySource class which appears to be missing a constructor in a published app.

If I try to call this constructor in AOT-published code, I get a MissingMethodException:

Unhandled Exception: System.MissingMethodException: Method not found: 'Void System.Diagnostics.ActivitySource..ctor(System.String)'.
at Internal.Runtime.TypeLoaderExceptionHelper.CreateMissingMethodException(ExceptionStringID, String) + 0x40
at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowMissingMethodException(ExceptionStringID, String) + 0x9
at Program.<

$>d__0.MoveNext() + 0x15
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.StartTStateMachine + 0x3f
at Program.$(String[]) + 0x2f
at Program.(String[] args) + 0x9

Reproduction Steps

  • Create a normal .NET 8 Console App with NativeAOT enabled.

  • Replace Program.cs

using System.Diagnostics;

var a = new ActivitySource("test");

Console.WriteLine(a.ToString());
  • Publish and run

  • App successfully runs to completion. ✔️

  • Install the System.Diagnostics.DiagnosticSource 9.0.0 package

  • Publish and run

  • Application crashes with MissingMethodException ❌

  • Downgrade System.Diagnostics.DiagnosticSource 9.0.0 package to 8.0.1

  • Publish and run

  • App successfully runs to completion. ✔️

Expected behavior

Constructor should be callable in AOT

Actual behavior

Constructor is not callable in AOT

Regression?

8.0.1 works, 9.0.0 does not.

Known Workarounds

No response

Configuration

.NET Version: 8.0
OS: Windows
Arch: x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions