Skip to content

Instantly share code, notes, and snippets.

@gfraiteur
Created February 15, 2012 10:16
Show Gist options
  • Save gfraiteur/1834882 to your computer and use it in GitHub Desktop.
Save gfraiteur/1834882 to your computer and use it in GitHub Desktop.
Debug a StackOverflowException in 1 minute with PostSharp
using System;
using PostSharp.Aspects;
using PostSharp.Aspects.Configuration;
using PostSharp.Aspects.Serialization;
using Resonance.Messenging.Diagnostics;
[assembly: StackOverflowDetection]
namespace Resonance.Messenging.Diagnostics
{
[OnMethodBoundaryAspectConfiguration(SerializerType = typeof(MsilAspectSerializer))]
public class StackOverflowDetectionAttribute : OnMethodBoundaryAspect
{
[ThreadStatic] private static int level;
public override void OnEntry(MethodExecutionArgs args)
{
level++;
if ( level > 100 ) throw new StackOverflowException();
}
public override void OnExit(MethodExecutionArgs args)
{
level--;
}
}
}
@gfraiteur
Copy link
Author

Aah, you were the inventor. I couldn't remember :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment