Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented missing logic for AotHelper + some diagnostics
  • Loading branch information
jamescrosswell committed Jul 10, 2025
commit 9d644c4a1b58f41f4bef191d1c7589dc2b8ecace
31 changes: 22 additions & 9 deletions src/Sentry/Internal/AotHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Sentry.CompilerServices;
using Sentry.Extensibility;

namespace Sentry.Internal;

Expand All @@ -15,29 +17,40 @@ static AotHelper()


[UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)]
private static bool CheckIsTrimmed()
internal static bool CheckIsTrimmed(IDiagnosticLogger? logger = null)
{
if (TryGetBoolean("publishtrimmed", out var trimmed))
if (TryGetBoolean("_IsPublishing", out var isPublishing) && isPublishing)
{
return trimmed;
}
logger?.LogDebug("Detected _IsPublishing");
if (TryGetBoolean("PublishSelfContained", out var selfContained) && selfContained)
{
logger?.LogDebug("Detected PublishSelfContained");
if (TryGetBoolean("PublishTrimmed", out var trimmed))
{
logger?.LogDebug("Detected PublishTrimmed");
return trimmed;
}
}

if (TryGetBoolean("publishaot", out var aot))
{
return aot;
if (TryGetBoolean("PublishAot", out var aot))
{
logger?.LogDebug($"Detected PublishAot: {aot}");
return aot;
}
}

// fallback check
logger?.LogDebug($"Stacktrace fallback");
var stackTrace = new StackTrace(false);
return stackTrace.GetFrame(0)?.GetMethod() is null;
}

private static bool TryGetBoolean(string key, out bool value)
{
value = false;
if (BuildProperties.Values?.TryGetValue(key, out var aotValue) ?? false)
if (BuildProperties.Values?.TryGetValue(key, out string? stringValue) ?? false)
{
if (bool.TryParse(aotValue, out var result))
if (bool.TryParse(stringValue, out var result))
{
value = result;
return true;
Expand Down
1 change: 1 addition & 0 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal static IHub InitHub(SentryOptions options)

#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable 0162 // Unreachable code on old .NET frameworks
AotHelper.CheckIsTrimmed(options.DiagnosticLogger);
options.LogDebug(AotHelper.IsTrimmed
? "This looks like a Native AOT application build."
: "This doesn't look like a Native AOT application build."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project>
<ItemGroup>
<CompilerVisibleProperty Include="_IsPublishing" />
<CompilerVisibleProperty Include="PublishAot" />
<CompilerVisibleProperty Include="UseDotNetNativeToolchain" />
<CompilerVisibleProperty Include="PublishTrimmed" />
<CompilerVisibleProperty Include="PublishSelfContained" />
<CompilerVisibleProperty Include="UseDotNetNativeToolchain" />
<CompilerVisibleProperty Include="SentryDisableSourceGenerator" />
<CompilerVisibleProperty Include="Configuration" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry/buildTransitive/Sentry.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
</ItemGroup>

<ItemGroup>
<CompilerVisibleProperty Include="_IsPublishing" />
<CompilerVisibleProperty Include="PublishAot" />
<CompilerVisibleProperty Include="UseDotNetNativeToolchain" />
<CompilerVisibleProperty Include="PublishTrimmed" />
<CompilerVisibleProperty Include="PublishSelfContained" />
<CompilerVisibleProperty Include="UseDotNetNativeToolchain" />
<CompilerVisibleProperty Include="SentryDisableSourceGenerator" />
<CompilerVisibleProperty Include="Configuration" />
</ItemGroup>
Expand Down
Loading