I'm trying to decompile a method programmatically using ICSharpCode. I'm able to decompile the entire type, but whenever I try to decompile a single method, I get a null reference exception. The approach is much like this question ICSharpCode.Decompiler + Mono.Cecil -> How to generate code for a single method?
The exception is thrown when invoking astBuilder.AddMethod. Any idea of what I'm missing. Or maybe recommendations for a different framework?
Thanks in advance!
Stacktrace:
at ICSharpCode.Decompiler.Ast.NameVariables.AssignNamesToVariables(DecompilerContext context, IEnumerable
1 parameters, IEnumerable
1 variables, ILBlock methodBody) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable1 parameters) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable
1 parameters) at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethodBody(MethodDefinition method, IEnumerable`1 parameters) at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition methodDef) at ICSharpCode.Decompiler.Ast.AstBuilder.AddMethod(MethodDefinition method) at CodeFlow.Decompile.DecompileMethod(String assemblyPath, String assemblyFile, String typeName, String methodName) in C:\Arbejdsfiler\DCFServices\Tools\CustomFxCopRules\CustomCodeAnalysis\CodeFlow\Decompile.cs:line 69