Stack overflow when adding outer closures


I've run into a stack overflow bug when decompiling with the DecompilerOptions.AnonymousDelegates.

The problem occurs when there's an anonymous delegate in a partial class that contributes to a class automatically generated using the Settings Designer (and probably other automatically generated classes as well).

Here's a small repro:
partial class FooSettings
   private FooSettings()
     var app = Application.Current;

     if (app != null)
        app.Exit += (sender, e) =>
           Debug.Print("Goodbye world!");
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "")]
public sealed partial class FooSettings
   private static FooSettings singleton = new FooSettings();
The situation causes the AddOuterClosures method in Closure Finder to recurse indefinitely.


tomenglert wrote Oct 3, 2015 at 9:25 AM

Looks like this is the same issue as in code contracts https://github.com/Microsoft/CodeContracts/issues/169