0

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, IEnumerable1 parameters, IEnumerable1 variables, ILBlock methodBody) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable1 parameters) at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable1 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

Community
  • 1
  • 1
jaspernygaard
  • 3,098
  • 5
  • 35
  • 52
  • Nobody been messing around with decompiling programmatically? – jaspernygaard Sep 03 '12 at 06:23
  • 1
    check my answer in the original article: [ICSharpCode.Decompiler + Mono.Cecil -> How to generate code for a single method?][1] [1]: http://stackoverflow.com/questions/9811448/icsharpcode-decompiler-mono-cecil-how-to-generate-code-for-a-single-method – Torsten Nov 22 '12 at 08:41
  • Torsten - works like a charm! Create an answer and mark it. – jaspernygaard Nov 29 '12 at 08:39

0 Answers0