Skip to content

Commit f89a99a

Browse files
committed
DOTNET-188: Adjust InnerException string before the '--- End of inner exception stack trace ---' line
1 parent f2f3f78 commit f89a99a

File tree

6 files changed

+94
-20
lines changed

6 files changed

+94
-20
lines changed

Src/StackifyLib.log4net.Tests/StackifyLib.log4net.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="log4net, Version=2.0.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
37-
<HintPath>..\packages\log4net.2.0.11\lib\net45\log4net.dll</HintPath>
36+
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
37+
<HintPath>..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
3838
</Reference>
3939
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4040
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4141
</Reference>
4242
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
4343
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
4444
</Reference>
45+
<Reference Include="StackifyLib, Version=2.2.15.0, Culture=neutral, PublicKeyToken=e0ba3f4d3f1bb0c2, processorArchitecture=MSIL">
46+
<HintPath>..\packages\StackifyLib.2.2.15\lib\net452\StackifyLib.dll</HintPath>
47+
</Reference>
4548
<Reference Include="System" />
4649
<Reference Include="System.Configuration" />
4750
<Reference Include="System.Core" />
51+
<Reference Include="System.Management" />
4852
<Reference Include="System.Web" />
4953
<Reference Include="System.Xml.Linq" />
5054
<Reference Include="System.Data.DataSetExtensions" />
@@ -65,10 +69,6 @@
6569
<Project>{7d98e5e3-a3e7-4613-8bb7-80a60d86a5e8}</Project>
6670
<Name>StackifyLib.log4net</Name>
6771
</ProjectReference>
68-
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj">
69-
<Project>{03cf7411-65e2-4998-a157-9224eca6199b}</Project>
70-
<Name>StackifyLib</Name>
71-
</ProjectReference>
7272
</ItemGroup>
7373
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7474
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="log4net" version="2.0.11" targetFramework="net452" />
3+
<package id="log4net" version="2.0.17" targetFramework="net452" />
44
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
55
<package id="NUnit" version="3.13.2" targetFramework="net452" />
6+
<package id="StackifyLib" version="2.2.15" targetFramework="net452" />
67
</packages>

Src/StackifyLib/Models/ErrorItem.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ public string FramesToString()
298298
{
299299
StringBuilder sb = new StringBuilder();
300300

301-
foreach (var item in this.StackTrace)
301+
if (InnerError != null)
302302
{
303-
sb.AppendFormat(" at {0}\r\n", item.Method);
303+
sb.Append(InnerError.FramesToString());
304+
sb.Append("--- End of inner exception stack trace ---\r\n");
304305
}
305306

306-
if (InnerError != null)
307+
foreach (var item in this.StackTrace)
307308
{
308-
sb.Append("--- End of inner exception stack trace ---\r\n");
309-
sb.Append(InnerError.FramesToString());
309+
sb.AppendFormat(" at {0}\r\n", item.Method);
310310
}
311311

312312
return sb.ToString();

Src/StackifyLibCore.sln

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30907.101
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35303.130
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackifyLib", "StackifyLib\StackifyLib.csproj", "{03CF7411-65E2-4998-A157-9224ECA6199B}"
77
EndProject
@@ -71,11 +71,9 @@ Global
7171
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
7272
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.Build.0 = Release|Any CPU
7373
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74-
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
7574
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
7675
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Release|Any CPU.Build.0 = Release|Any CPU
7776
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
78-
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
7977
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
8078
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Release|Any CPU.Build.0 = Release|Any CPU
8179
{CB09D719-F393-413D-B5CD-E0125543AD24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -99,15 +97,12 @@ Global
9997
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
10098
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.Build.0 = Release|Any CPU
10199
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102-
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
103100
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
104101
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Release|Any CPU.Build.0 = Release|Any CPU
105102
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
106-
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
107103
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
108104
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Release|Any CPU.Build.0 = Release|Any CPU
109105
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
110-
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Debug|Any CPU.Build.0 = Debug|Any CPU
111106
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Release|Any CPU.ActiveCfg = Release|Any CPU
112107
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Release|Any CPU.Build.0 = Release|Any CPU
113108
{18F96933-468E-4104-961E-0C68A5EF2B29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2024 BMC Software, Inc.
2+
// Copyright (c) 2021-2024 Netreo
3+
// Copyright (c) 2019 Stackify
4+
using StackifyLib.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Xunit;
12+
using Moq;
13+
14+
namespace StackifyLib.UnitTests.Models
15+
{
16+
public class ErrorItem_Tests
17+
{
18+
19+
[Fact]
20+
public async Task TestExceptionStringWithInnerException()
21+
{
22+
var expectedString = string.Join(
23+
Environment.NewLine,
24+
"System.Exception: Wrapping the exception to see the differences between outer and inner exceptions. ---> System.Exception: Throwing this exception to see all properties like stacktrace filled",
25+
" at StackifyLib.UnitTests.Models.ExampleService.ThrowInnerException()",
26+
" at StackifyLib.UnitTests.Models.ExampleService.CreateCaughtException()",
27+
"--- End of inner exception stack trace ---",
28+
" at StackifyLib.UnitTests.Models.ExampleService.ThrowOuterException(System.Exception)",
29+
" at StackifyLib.UnitTests.Models.ExampleService.CreateCaughtException()",
30+
" at StackifyLib.UnitTests.Models.ErrorItem_Tests+<TestExceptionStringWithInnerException>d__0.MoveNext()",
31+
""
32+
);
33+
try
34+
{
35+
//ExampleService service = new ExampleService();
36+
ExampleService.CreateCaughtException();
37+
}
38+
catch (Exception ex)
39+
{
40+
//PrintExceptionInfo(ex);
41+
var exceptionString = new ErrorItem(ex).ToString();
42+
Assert.Contains(expectedString, exceptionString);
43+
}
44+
}
45+
}
46+
47+
class ExampleService
48+
{
49+
public static Exception CreateCaughtException()
50+
{
51+
try
52+
{
53+
try
54+
{
55+
ThrowInnerException();
56+
}
57+
catch (Exception exception)
58+
{
59+
ThrowOuterException(exception);
60+
}
61+
}
62+
catch (Exception)
63+
{
64+
throw;
65+
}
66+
// NOTE: never reached, but needed for the compiler.
67+
return null;
68+
}
69+
private static void ThrowOuterException(Exception exception)
70+
{
71+
throw new Exception("Wrapping the exception to see the differences between outer and inner exceptions.", exception);
72+
}
73+
private static void ThrowInnerException()
74+
{
75+
throw new Exception("Throwing this exception to see all properties like stacktrace filled");
76+
}
77+
}
78+
}

test/StackifyLib.UnitTests/StackifyLib.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="FluentAssertions" Version="5.5.3" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2020
<PackageReference Include="Moq" Version="4.20.70" />
2121
<PackageReference Include="xunit" Version="2.8.1" />
2222
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />

0 commit comments

Comments
 (0)