Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3ae2cf0
Make internal
jamescrosswell Nov 1, 2023
dfdee44
Update EnhancedStackFrame.cs
jamescrosswell Nov 1, 2023
137ef34
Update PortablePdbReader.cs
jamescrosswell Dec 18, 2023
2e7a3fd
Update PortablePdbReader.cs
jamescrosswell Dec 18, 2023
27c0910
Update PortablePdbReader.cs
jamescrosswell Dec 19, 2023
5ac4f5c
Improve native AOT compatibility
MichalStrehovsky Mar 14, 2024
5af18f7
Update Directory.Build.props
jamescrosswell Apr 24, 2024
6e15986
Update ExceptionExtensions.cs
jamescrosswell Apr 24, 2024
f37bc70
Merge branch 'main' into native-aot
jamescrosswell Apr 24, 2024
cd8c754
Update EnhancedStackFrame.cs
jamescrosswell Apr 24, 2024
11a87af
Update ExceptionExtensions.cs
jamescrosswell Apr 24, 2024
ad4c115
Ran modules/make-internal.sh
jamescrosswell Sep 24, 2024
b1dd53b
Disable file system analyzer warning
Nov 10, 2024
fe04751
Make trim warnings more specific
jamescrosswell Dec 12, 2024
83e3015
Reverted internal member visibility
jamescrosswell Feb 26, 2025
6ba5b3c
Merge branch 'main' into update-main
jamescrosswell Feb 26, 2025
c4459d0
Class Visibility
jamescrosswell Feb 26, 2025
64b9f29
Dropped EOL targets and handled warnings
jamescrosswell Feb 27, 2025
ce8a49f
Update Ben.Demystifier.sln
jamescrosswell Feb 27, 2025
e787c45
Update pull-request.yaml
jamescrosswell Feb 27, 2025
ca05207
Update Ben.Demystifier.Benchmarks.csproj
jamescrosswell Feb 27, 2025
8ca08b2
Update pull-request.yaml
jamescrosswell Feb 27, 2025
bbffa7c
Dropped netcoreapp2.1 target for tests
jamescrosswell Feb 27, 2025
1d47fe4
Update tests
jamescrosswell Feb 27, 2025
57fe6e5
Update Ben.Demystifier.Test.csproj
jamescrosswell Feb 27, 2025
68b350e
Upload test results
jamescrosswell Feb 27, 2025
407d108
Update pull-request.yaml
jamescrosswell Feb 27, 2025
0d6fa58
Update pull-request.yaml
jamescrosswell Feb 27, 2025
acaa1a7
.
jamescrosswell Feb 27, 2025
1efebe7
Update pull-request.yaml
jamescrosswell Feb 27, 2025
9de07b6
Update Directory.Build.props
jamescrosswell Feb 27, 2025
34d8e1d
.
jamescrosswell Feb 27, 2025
ec24a6f
Update Ben.Demystifier.Test.csproj
jamescrosswell Feb 27, 2025
f9d7b9c
Update Ben.Demystifier.Test.csproj
jamescrosswell Feb 27, 2025
1e46ef7
Revert to net6.0
jamescrosswell Feb 27, 2025
ea21538
Update pull-request.yaml
jamescrosswell Feb 27, 2025
45c7c5e
.
jamescrosswell Feb 27, 2025
013f186
Update Directory.Build.props
jamescrosswell Feb 27, 2025
32a8bb4
.
jamescrosswell Feb 27, 2025
78afd06
Update pull-request.yaml
jamescrosswell Feb 27, 2025
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
36 changes: 17 additions & 19 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
build:
name: "Build for PR"
runs-on: ${{ matrix.os }}
env:
DOTNET_NOLOGO: true
strategy:
fail-fast: false
matrix:
Expand All @@ -22,22 +20,16 @@ jobs:
with:
fetch-depth: 0

- name: Setup .NET SDK (v2.1)
uses: actions/setup-dotnet@v3
with:
dotnet-version: '2.1.818'
- name: Setup .NET SDK (v3.1)
uses: actions/setup-dotnet@v3
with:
dotnet-version: '3.1.414'
- name: Setup .NET SDK (v5.0)
uses: actions/setup-dotnet@v3
with:
dotnet-version: '5.0.402'
- name: Setup .NET SDK (v6.0)
uses: actions/setup-dotnet@v3
- name: Set environment variables
run: |
echo "DOTNET_NOLOGO=true" >> $GITHUB_ENV

- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.417'
dotnet-version: |
6.0.417
9.0.100

- name: Get .NET information
run: dotnet --info
Expand All @@ -46,5 +38,11 @@ jobs:
run: dotnet build -c ${{ matrix.config }}

- name: "Test"
run: dotnet test -c ${{ matrix.config }}

run: dotnet test -c ${{ matrix.config }} -l "trx;LogFilePrefix=testresults_${{ runner.os }}_${{ matrix.config }}"

- name: "Upload Test Results"
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ runner.os }}-${{ matrix.config }}.trx
path: '**/testresults_*.trx'
1 change: 0 additions & 1 deletion Ben.Demystifier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackTrace", "sample\StackT
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5937ACDF-0059-488E-9604-D84689C72933}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
Directory.Build.props = Directory.Build.props
README.md = README.md
Expand Down
7 changes: 6 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- We need to support old stuff. Applications should definitely address these advisory warnings though. -->
<NoWarn>$(NoWarn);NU1902;NU1903</NoWarn>
<!-- https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/dotnet-restore-audit#version-introduced -->
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)'=='.csproj'">
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="All" />
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Which is far less helpful, and close to jibberish in places
* **iterators**

Cannot determine overload `<Iterator>d__3.MoveNext()` rather than `Iterator(int startAt)+MoveNext()`

* **Linq**

Cannot determine overload
Expand All @@ -124,6 +125,7 @@ Which is far less helpful, and close to jibberish in places
rather than

`Linq.Enumerable+SelectEnumerableIterator<TSource, TResult>.MoveNext()`

* **async**

Cannot determine overload and no modifier such as `async`
Expand All @@ -147,19 +149,23 @@ Which is far less helpful, and close to jibberish in places
* **lambdas**

Mostly jibberish `<>c__DisplayClass2_0.<.ctor>b__0(Object state)` with a suggestion of where they are declared but no hint if there are multiple overloads of the method.

* **local functions**

Mostly jibberish `<RefMethod>g__LocalFuncParam|10_0(String val, <>c__DisplayClass10_0& )` with a suggestion of where they are declared but no hint if there are multiple overloads of the method.

* **generic parameters**

Not resolved, only an indication of the number `RunLambda(Func``1 lambda)` rather than `RunLambda(Func<string> lambda)`

* **value tuples**

Do not match code, output as `ValueTuple``2 param` rather than `(string val, bool) param`

* **primitive types**

Do not match code, output as `Int64`, `Boolean`, `String` rather than `long`, `bool`, `string`

* **return types**

Skipped entirely from method signature
Expand All @@ -168,6 +174,6 @@ Which is far less helpful, and close to jibberish in places

To run benchmarks from the repository root:
```
dotnet run -p .\test\Ben.Demystifier.Benchmarks\ -c Release -f netcoreapp2.0 All
dotnet run -p .\test\Ben.Demystifier.Benchmarks\ -c Release -f net6.0 All
```
<sub>Note: we're only kicking off via `netcoreapp2.0`, benchmarks will run for all configured platforms like `net462`.</sub>
<sub>Note: we're only kicking off via `net8.0`, benchmarks will run for all configured platforms like `net462`.</sub>
2 changes: 1 addition & 1 deletion sample/FSharpStackTrace/FSharpStackTrace.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions sample/StackTrace/StackTrace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ben.Demystifier\Ben.Demystifier.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.30" />
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.30" AllowExplicitVersion="true" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Ben.Demystifier/Ben.Demystifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net45;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net462;net6.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<PackageIcon>icon.png</PackageIcon>
Expand Down
2 changes: 2 additions & 0 deletions src/Ben.Demystifier/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ internal static class Constants
{
internal const string TrimWarning = "This class should be avoided when compiling for AOT.";
internal const string SuppressionResurfaced = "Surfaced by parent class";
internal const string AvoidAtRuntime = "Non-trimmable code is avoided at runtime";
internal const string SingleFileFallback = "Fallback functionality for single files";
}
2 changes: 1 addition & 1 deletion src/Ben.Demystifier/EnhancedStackFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Diagnostics
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
internal class EnhancedStackFrame : StackFrame
public class EnhancedStackFrame : StackFrame
{
private readonly string? _fileName;
private readonly int _lineNumber;
Expand Down
36 changes: 33 additions & 3 deletions src/Ben.Demystifier/EnhancedStackTrace.Frames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ namespace System.Diagnostics
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
internal partial class EnhancedStackTrace
public partial class EnhancedStackTrace
{
private static readonly Type? StackTraceHiddenAttributeType = Type.GetType("System.Diagnostics.StackTraceHiddenAttribute", false);
private static readonly Type? AsyncIteratorStateMachineAttributeType = Type.GetType("System.Runtime.CompilerServices.AsyncIteratorStateMachineAttribute", false);

#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = Constants.AvoidAtRuntime)]
#endif
static EnhancedStackTrace()
{
if (AsyncIteratorStateMachineAttributeType != null) return;
Expand All @@ -35,15 +38,18 @@ static EnhancedStackTrace()
try
{
mba = Assembly.Load("Microsoft.Bcl.AsyncInterfaces");
AsyncIteratorStateMachineAttributeType = mba.GetType("System.Runtime.CompilerServices.AsyncIteratorStateMachineAttribute", false);
}
catch
{
return;
}

AsyncIteratorStateMachineAttributeType = mba.GetType("System.Runtime.CompilerServices.AsyncIteratorStateMachineAttribute", false);
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static List<EnhancedStackFrame> GetFrames(Exception exception)
{
if (exception == null)
Expand All @@ -57,6 +63,9 @@ private static List<EnhancedStackFrame> GetFrames(Exception exception)
return GetFrames(stackTrace);
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public static List<EnhancedStackFrame> GetFrames(StackTrace stackTrace)
{
var frames = new List<EnhancedStackFrame>();
Expand Down Expand Up @@ -124,6 +133,9 @@ public static List<EnhancedStackFrame> GetFrames(StackTrace stackTrace)
return frames;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public static ResolvedMethod GetMethodDisplayString(MethodBase originMethod)
{
var method = originMethod;
Expand Down Expand Up @@ -300,6 +312,9 @@ private static bool IsFSharpAsync(MethodBase method)
return false;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static bool TryResolveGeneratedName(ref MethodBase method, out Type? type, out string methodName, out string? subMethodName, out GeneratedNameKind kind, out int? ordinal)
{
kind = GeneratedNameKind.None;
Expand Down Expand Up @@ -386,6 +401,9 @@ private static bool TryResolveGeneratedName(ref MethodBase method, out Type? typ
return false;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static bool TryResolveSourceMethod(IEnumerable<MethodBase> candidateMethods, GeneratedNameKind kind, string? matchHint, ref MethodBase method, ref Type? type, out int? ordinal)
{
ordinal = null;
Expand Down Expand Up @@ -455,6 +473,9 @@ private static bool TryResolveSourceMethod(IEnumerable<MethodBase> candidateMeth
return false;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static void GetOrdinal(MethodBase method, ref int? ordinal)
{
var lamdaStart = method.Name.IndexOf((char)GeneratedNameKind.LambdaMethod + "__") + 3;
Expand Down Expand Up @@ -610,6 +631,9 @@ private static string GetPrefix(ParameterInfo parameter)
return string.Empty;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static ResolvedParameter GetParameter(ParameterInfo parameter)
{
var prefix = GetPrefix(parameter);
Expand All @@ -619,7 +643,7 @@ private static ResolvedParameter GetParameter(ParameterInfo parameter)
{
var customAttribs = parameter.GetCustomAttributes(inherit: false);

#if NET45
#if NETFRAMEWORK
var tupleNameAttribute = customAttribs.OfType<Attribute>().FirstOrDefault(a => a.IsTupleElementNameAttribute());

var tupleNames = tupleNameAttribute?.GetTransformerNames();
Expand Down Expand Up @@ -648,6 +672,9 @@ private static ResolvedParameter GetParameter(ParameterInfo parameter)
};
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
private static ResolvedParameter GetValueTupleParameter(IList<string?> tupleNames, string prefix, string? name, Type parameterType)
{
return new ValueTupleResolvedParameter(parameterType, tupleNames)
Expand Down Expand Up @@ -867,6 +894,9 @@ private static bool IsStackTraceHidden(MemberInfo memberInfo)
return false;
}

#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
// https://github.com/dotnet/runtime/blob/c985bdcec2a9190e733bcada413a193d5ff60c0d/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs#L375-L430
private static bool TryResolveStateMachineMethod(ref MethodBase method, out Type declaringType)
{
Expand Down
14 changes: 12 additions & 2 deletions src/Ben.Demystifier/EnhancedStackTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic.Enumerable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using Ben.Demystifier;

namespace System.Diagnostics
{
internal partial class EnhancedStackTrace : StackTrace, IEnumerable<EnhancedStackFrame>
public partial class EnhancedStackTrace : StackTrace, IEnumerable<EnhancedStackFrame>
{
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public static EnhancedStackTrace Current() => new EnhancedStackTrace(new StackTrace(1 /* skip this one frame */, true));

private readonly List<EnhancedStackFrame> _frames;
Expand All @@ -26,6 +31,9 @@ internal partial class EnhancedStackTrace : StackTrace, IEnumerable<EnhancedStac
// Exceptions:
// T:System.ArgumentNullException:
// The parameter e is null.
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public EnhancedStackTrace(Exception e)
{
if (e == null)
Expand All @@ -36,7 +44,9 @@ public EnhancedStackTrace(Exception e)
_frames = GetFrames(e);
}


#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public EnhancedStackTrace(StackTrace stackTrace)
{
if (stackTrace == null)
Expand Down
2 changes: 1 addition & 1 deletion src/Ben.Demystifier/Enumerable/EnumerableIList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static class EnumerableIList
public static EnumerableIList<T> Create<T>(IList<T> list) => new EnumerableIList<T>(list);
}

internal struct EnumerableIList<T> : IEnumerableIList<T>, IList<T>
public struct EnumerableIList<T> : IEnumerableIList<T>, IList<T>
{
private readonly IList<T> _list;

Expand Down
2 changes: 1 addition & 1 deletion src/Ben.Demystifier/Enumerable/EnumeratorIList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Collections.Generic.Enumerable
{
internal struct EnumeratorIList<T> : IEnumerator<T>
public struct EnumeratorIList<T> : IEnumerator<T>
{
private readonly IList<T> _list;
private int _index;
Expand Down
8 changes: 4 additions & 4 deletions src/Ben.Demystifier/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
using Ben.Demystifier;
using Constants = Ben.Demystifier.Constants;

namespace System.Diagnostics
{
Expand All @@ -23,9 +23,9 @@ private static void SetStackTracesString(this Exception exception, string value)
/// <summary>
/// Demystifies the given <paramref name="exception"/> and tracks the original stack traces for the whole exception tree.
/// </summary>
#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = Constants.SuppressionResurfaced)]
#endif
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode(Constants.TrimWarning)]
#endif
public static T Demystify<T>(this T exception) where T : Exception
{
try
Expand Down
Loading