dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.36k stars 4.74k forks source link

Possible System.Diagnostics.DiagnosticSource trimming issue #109872

Open jamiewinder opened 1 hour ago

jamiewinder commented 1 hour ago

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

using System.Diagnostics;

var a = new ActivitySource("test");

Console.WriteLine(a.ToString());

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[bot] commented 1 hour ago

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

dotnet-policy-service[bot] commented 1 hour ago

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

tarekgh commented 1 hour ago

@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 commented 1 hour ago

Making the app target net9 makes the issue disappear.

jkotas commented 52 minutes ago

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.