Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible System.Diagnostics.DiagnosticSource trimming issue #109872

Closed
jamiewinder opened this issue Nov 15, 2024 · 10 comments · Fixed by #109988
Closed

Possible System.Diagnostics.DiagnosticSource trimming issue #109872

jamiewinder opened this issue Nov 15, 2024 · 10 comments · Fixed by #109988
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jamiewinder
Copy link

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

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 15, 2024
Copy link
Contributor

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@tarekgh
Copy link
Member

tarekgh commented Nov 15, 2024

@agocke, @MichalStrehovsky I confirmed the issue reproduce. The constructor exists in the ActivitySource class System.Diagnostics.ActivitySource..ctor(System.String). Note, this constructor didn't exist in net8 version of the library. Are we performing the trimming against the assembly shipped with the framework?

The ILLink.Substitutions.xml in both net8 and net9 versions of System.Diagnostics.DiagnosticSource don't have any section for ActivitySource type. Could you please have a look?

@tarekgh
Copy link
Member

tarekgh commented Nov 15, 2024

Making the app target net9 makes the issue disappear.

@tarekgh tarekgh modified the milestones: 9.0.x, 8.0.x Nov 15, 2024
@jkotas
Copy link
Member

jkotas commented Nov 15, 2024

Looks like a dup of #108909 and related issues.

The conflicts between inbox assemblies and OOB packages are not resolved correctly for AOT compilation. The inbox assembly wins even when the OOB packages provides higher version.

@tarekgh
Copy link
Member

tarekgh commented Nov 15, 2024

I hope we can service the fix of this issue on net8 if possible. My understanding is that OpenTelemetry started to take dependency on System.Diagnostics.DiagnosticSource v9.0. This will make net8 users broken if they want to build as AOT.

CC @reyang @noahfalk

@jamiewinder
Copy link
Author

@tarekgh This is indeed how I first encountered the issue before reducing it down to the above. It isn't just OpenTelemetry either, a lot of the recently released Microsoft 9.x libraries now have this dependency, rendering them unusable with AOT and .NET 8.

@jmlane
Copy link

jmlane commented Nov 17, 2024

I'm seeing this issue in Blazor WASM .NET 8 when using 9.x packages as well (Microsoft.AspNetCore.SignalR.Client 9.0.0 specifically).

@MichalStrehovsky
Copy link
Member

I'm seeing this issue in Blazor WASM .NET 8 when using 9.x packages as well (Microsoft.AspNetCore.SignalR.Client 9.0.0 specifically).

Blazor WASM is guaranteed to be a different issue. Could you please open a new issue so that it can be routed to the right people?

@agocke
Copy link
Member

agocke commented Nov 18, 2024

Closing as dup of #108909

I've prioritized fixing that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants