Here's the stack trace:
System.ArgumentNullException: Value cannot be null.
Parameter name: then
at
Cecil.FlowAnalysis.ActionFlow.ConditionalBranchActionBlock.SetTargets
(ActionBlock then, ActionBlock else_) in C:\Users\Phil\Desktop
\Development\cecil\flowanalysis\Cecil.FlowAnalysis\ActionFlow
\ConditionalBranchActionBlock.cs:line 74
at
Cecil.FlowAnalysis.ActionFlow.ActionFlowGraphBuilder.ConnectActionBlocks
() in C:\Users\Phil\Desktop\Development\cecil\flowanalysis
\Cecil.FlowAnalysis\ActionFlow\ActionFlowGraphBuilder.cs:line 154
at Cecil.FlowAnalysis.ActionFlow.ActionFlowGraphBuilder.Run() in C:
\Users\Phil\Desktop\Development\cecil\flowanalysis\Cecil.FlowAnalysis
\ActionFlow\ActionFlowGraphBuilder.cs:line 70
at Cecil.FlowAnalysis.ActionFlow.ActionFlowGraphBuilder.BuildGraph
() in C:\Users\Phil\Desktop\Development\cecil\flowanalysis
\Cecil.FlowAnalysis\ActionFlow\ActionFlowGraphBuilder.cs:line 62
at Cecil.FlowAnalysis.FlowGraphFactory.CreateActionFlowGraph
(ControlFlowGraph cfg) in C:\Users\Phil\Desktop\Development\cecil
\flowanalysis\Cecil.FlowAnalysis\FlowGraphFactory.cs:line 48
at FlowAnalysis.Program.Main(String[] args) in C:\Users\Phil\Desktop
\Development\spikes\FlowAnalysis\FlowAnalysis\Program.cs:line 29
Here's the assembly that I opened using Cecil and Cecil.FlowAnalysis:
public class Foo
{
public void DoSomething(bool someCondition)
{
if (someCondition)
{
Console.WriteLine("The condition is true");
}
else
{
Console.WriteLine("The condition is false");
}
}
}
...and here's the client code that I used to make it crash:
class Program
{
static void Main(string[] args)
{
var filename = typeof(Foo).Assembly.Location;
var assembly = AssemblyFactory.GetAssembly(filename);
var module = assembly.MainModule;
var types = module.Types.Cast<TypeDefinition>();
var fooType = types.Where(t => t.Name == "Foo").First();
var methods = fooType.Methods.Cast<MethodDefinition>();
var targetMethod = methods.First();
try
{
var cfg = FlowGraphFactory.CreateControlFlowGraph
(targetMethod);
// Cecil.FlowAnalysis crashes on the next line
var afg = FlowGraphFactory.CreateActionFlowGraph(cfg);
}
catch(Exception ex)
{
var message = ex.ToString();
Debug.WriteLine(message);
throw;
}
return;
}
Now is there something I'm doing wrong here and is there any way to
fix this or work around this?
--
--
mono-cecil