Skip to content
Open
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 @@ -7,7 +7,7 @@ namespace System.Diagnostics
/// Types and Methods attributed with StackTraceHidden will be omitted from the stack trace text shown in StackTrace.ToString()
/// and Exception.StackTrace
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct, Inherited = false)]
public sealed class StackTraceHiddenAttribute : Attribute
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class ExcludeFromCodeCoverageAttribute : Attribute
{
public ExcludeFromCodeCoverageAttribute() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Diagnostics
/// Types and Methods attributed with StackTraceHidden will be omitted from the stack trace text shown in StackTrace.ToString()
/// and Exception.StackTrace
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct, Inherited = false)]
public sealed class StackTraceHiddenAttribute : Attribute
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8892,7 +8892,7 @@ public DebuggerVisualizerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyA
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public string VisualizerTypeName { get { throw null; } }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, Inherited=false)]
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Struct, Inherited=false)]
public sealed partial class StackTraceHiddenAttribute : System.Attribute
{
public StackTraceHiddenAttribute() { }
Expand Down Expand Up @@ -9012,7 +9012,7 @@ public DynamicDependencyAttribute(string memberSignature, System.Type type) { }
public System.Type? Type { get { throw null; } }
public string? TypeName { get { throw null; } }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false, AllowMultiple=false)]
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false, AllowMultiple=false)]
public sealed partial class ExcludeFromCodeCoverageAttribute : System.Attribute
{
public ExcludeFromCodeCoverageAttribute() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,18 @@ public void ExcludeFromCodeCoverageAttribute_Instantiate()
{
new ExcludeFromCodeCoverageAttribute();
}

[Fact]
public void ExcludeFromCodeCoverageAttribute_CanApplyToInterface()
{
var attr = typeof(IExcludedInterface).GetCustomAttributes(typeof(ExcludeFromCodeCoverageAttribute), false);
Assert.Single(attr);
}

[ExcludeFromCodeCoverage]
private interface IExcludedInterface
{
void DoSomething();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,29 @@ internal struct HiddenStruct
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
internal string GetStackTraceMethodC() => Environment.StackTrace;
}

[Fact]
public void InterfaceHidden_EnvironmentStackTrace()
{
string stacktrace = ((IHiddenInterface)new HiddenInterfaceImpl()).GetStackTraceMethodA();
Assert.DoesNotContain(nameof(IHiddenInterface.GetStackTraceMethodA), stacktrace);
Assert.DoesNotContain(nameof(IHiddenInterface.GetStackTraceMethodB), stacktrace);
Assert.DoesNotContain(nameof(IHiddenInterface.GetStackTraceMethodC), stacktrace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you add a similar INotHiddenInterface and validate that with exactly the same setup except for the attribute that those stacktraces do contain the relevant method names?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

[StackTraceHidden]
internal interface IHiddenInterface
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
string GetStackTraceMethodA() => GetStackTraceMethodB();

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
string GetStackTraceMethodB() => GetStackTraceMethodC();

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
string GetStackTraceMethodC() => Environment.StackTrace;
}

internal class HiddenInterfaceImpl : IHiddenInterface { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,34 @@
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>net10.0/System.Diagnostics.Tools.dll</Left>
<Right>net11.0/System.Diagnostics.Tools.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.StackTraceHiddenAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>net10.0/System.Runtime.dll</Left>
<Right>net11.0/System.Runtime.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>net10.0/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>net10.0/System.dll</Left>
<Right>net11.0/System.dll</Right>
</Suppression>
</Suppressions>
6 changes: 6 additions & 0 deletions src/libraries/apicompat/ApiCompatBaseline.netstandard2.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,10 @@
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net11.0/netstandard.dll</Right>
</Suppression>
</Suppressions>
Loading