I ran into a problem this weekend where method 1 called method 2 which called method 3 which caught exception, and within the exception handling method 1 was called again...
M1 -> M2 -> M3 -> M1 ....
The problem became obvious and easy to fix, once the problem happened.
Does anyone know of a tool to detect problems like this in a .NET application?
To do this right, you need a global call graph over the C# application, computed using C# semantics and what amounts to a points-to analysis, arguably including the libraries it calls. With such a call graph, you could enumerate the cycles in it, and those would be the candidates to check.
I don't know where you would get a tool that compute such a global call graph for C#, off the shelf.
You could approximate this using simple code scanning techniques. For each method M, extract the apparant set of calls it contains as identifiers I. Mostly they will appear as syntax that looks like identifier( After this step you have M_i -> I. You can build this as an (extermely conservative) basic call graph, and then compute the transitive closure. With that, you have an approximate call graph with cycles, and you can carry out your cycle analysis. This would mass methods passed by names, and other cases, but it might be good enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With