Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace Internal.Runtime.InteropServices
internal static class InMemoryAssemblyLoader
{
[FeatureSwitchDefinition("System.Runtime.InteropServices.EnableCppCLIHostActivation")]
private static bool IsSupported { get; } = InitializeIsSupported();
private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableCppCLIHostActivation", out bool isSupported) ? isSupported : true;
private static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableCppCLIHostActivation", out bool isSupported) ? isSupported : true;

/// <summary>
/// Loads an assembly that has already been loaded into memory by the OS loader as a native module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public StackFrameHelper()
// rgiLineNumber and rgiColumnNumber fields using the portable PDB reader if not already
// done by GetStackFramesInternal (on Windows for old PDB format).
//

internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception)
{
StackTrace.GetStackFramesInternal(this, fNeedFileInfo, exception);

if (!fNeedFileInfo)

if (!StackTrace.IsLineNumberSupported || !fNeedFileInfo)
return;

// Check if this function is being reentered because of an exception in the code below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public class Meter : IDisposable
internal bool Disposed { get; private set; }

[FeatureSwitchDefinition("System.Diagnostics.Metrics.Meter.IsSupported")]
internal static bool IsSupported { get; } = InitializeIsSupported();

private static bool InitializeIsSupported() =>
AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out bool isSupported) ? isSupported : true;
internal static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out bool isSupported) ? isSupported : true;

/// <summary>
/// Initialize a new instance of the Meter using the <see cref="MeterOptions" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ internal static partial class ComponentActivator
private const int HostFeatureDisabled = unchecked((int)0x800080a7);

[FeatureSwitchDefinition("System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting")]
private static bool IsSupported { get; } = InitializeIsSupported();

private static bool InitializeIsSupported() => AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting", out bool isSupported) ? isSupported : true;
private static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting", out bool isSupported) ? isSupported : true;

public delegate int ComponentEntryPoint(IntPtr args, int sizeBytes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public static void BreakForUserUnhandledException(Exception exception)
}

[FeatureSwitchDefinition("System.Diagnostics.Debugger.IsSupported")]
internal static bool IsSupported { get; } = InitializeIsSupported();

private static bool InitializeIsSupported()
{
return AppContext.TryGetSwitch("System.Diagnostics.Debugger.IsSupported", out bool isSupported)
? isSupported
: true;
}
internal static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.Debugger.IsSupported", out bool isSupported) ? isSupported : true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace System.Diagnostics
public partial class StackTrace
{
[FeatureSwitchDefinition("System.Diagnostics.StackTrace.IsSupported")]
internal static bool IsSupported { get; } = InitializeIsSupported();
internal static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.StackTrace.IsSupported", out bool isSupported) ? isSupported : true;

private static bool InitializeIsSupported() =>
AppContext.TryGetSwitch("System.Diagnostics.StackTrace.IsSupported", out bool isSupported) ? isSupported : true;
[FeatureSwitchDefinition("System.Diagnostics.StackTrace.IsLineNumberSupported")]
internal static bool IsLineNumberSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.StackTrace.IsLineNumberSupported", out bool isSupported) ? isSupported : true;

public const int METHODS_TO_SKIP = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,10 @@ public partial class EventSource : IDisposable
private static readonly bool AllowDuplicateSourceNames = AppContext.TryGetSwitch(DuplicateSourceNamesSwitch, out bool isEnabled) ? isEnabled : false;

[FeatureSwitchDefinition("System.Diagnostics.Tracing.EventSource.IsSupported")]
internal static bool IsSupported { get; } = InitializeIsSupported();

private static bool InitializeIsSupported() =>
AppContext.TryGetSwitch("System.Diagnostics.Tracing.EventSource.IsSupported", out bool isSupported) ? isSupported : true;
internal static bool IsSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.Tracing.EventSource.IsSupported", out bool isSupported) ? isSupported : true;

[FeatureSwitchDefinition("System.Diagnostics.Metrics.Meter.IsSupported")]
internal static bool IsMeterSupported { get; } = InitializeIsMeterSupported();

private static bool InitializeIsMeterSupported() =>
AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out bool isSupported) ? isSupported : true;
internal static bool IsMeterSupported { get; } = AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out bool isSupported) ? isSupported : true;

#if FEATURE_EVENTSOURCE_XPLAT
#pragma warning disable CA1823 // field is used to keep listener alive
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Reflection;


/// <summary>
/// Tests that StackTraceSymbols and dependencies are not included in a trimmed app targeting browser.
/// The idea is that the runtime should not depend on these types when running in a browser with DebugSymbols == false.
/// Motivation: application size.
/// </summary>
class Program
{
static int Main(string[] args)
{
var symbolsType = GetTypeByName("StackTraceSymbols");
if (symbolsType != null)
{
Console.WriteLine("Failed StackTraceSymbols");
return -1;
}
return 100;
}

// make reflection trimmer incompatible
static Type GetTypeByName(string typeName)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
var type = assembly.GetType("System.Diagnostics." + typeName);
if (type != null)
{
return type;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(WasmEnableThreads)' != 'true'">
<TestConsoleAppSourceFiles Include="BrowserDoesNotIncludeConcurrentTypes.cs" />
<TestConsoleAppSourceFiles Include="BrowserDoesNotIncludeStackTraceSymbols.cs">
<DisabledProperties>DebugSymbols</DisabledProperties>
</TestConsoleAppSourceFiles>
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,17 @@ Copyright (c) .NET Foundation. All rights reserved.
<_WasmBundlerFriendlyBootConfig>$(WasmBundlerFriendlyBootConfig)</_WasmBundlerFriendlyBootConfig>
<_WasmBundlerFriendlyBootConfig Condition="'$(_WasmBundlerFriendlyBootConfig)' == ''">false</_WasmBundlerFriendlyBootConfig>

<!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
<!-- Workaround for https://github.com/dotnet/sdk/issues/12114 -->
<PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
</PropertyGroup>

<!-- Trim support for line number in stack traces by default -->
<PropertyGroup>
<StackTraceLineNumberSupport Condition="'$(StackTraceLineNumberSupport)' == '' and ('$(StackTraceSupport)' == 'false' or '$(DebugSymbols)' != 'true')">false</StackTraceLineNumberSupport>
</PropertyGroup>
<ItemGroup Condition="'$(StackTraceLineNumberSupport)' == 'false'">
<RuntimeHostConfigurationOption Include="System.Diagnostics.StackTrace.IsLineNumberSupported" Value="false" Trim="true" />
</ItemGroup>
<Warning Text="Custom Blazor cache has been removed and setting 'BlazorCacheBootResources' has no effect." Condition="'$(_BlazorCacheBootResources)' != 'false' and '$(_TargetingNET100OrLater)' == 'true'" />
</Target>

Expand Down
Loading