13

I am using the Mono.Cecil DLL file and writing this code:

AssemblyDefinition sourceAssembly = AssemblyFactory.GetAssembly(assemblyPath);

My project is not getting compiled, because it is not able to find the class "AssemblyFactory". As if this class is not present in the DLL file at all. I have added the mono.cecil.dll file as a reference to my project. Is this class present somewhere outside the DLL file, maybe in some other DLL file at the .NET level?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
samar
  • 5,021
  • 9
  • 47
  • 71
  • if there's anything else you want to know about Mono.Cecil, I'd be glad to help in separate questions. In the meantime, this one is answered. – Jb Evain Nov 12 '11 at 09:07
  • Similar to *[How to save a changed assembly using Mono.Cecil?](http://stackoverflow.com/questions/13682491)* (in that *AssemblyFactory* no longer exists in later versions of Mono.Cecil). – Peter Mortensen Sep 19 '13 at 20:20

1 Answers1

24

This simply means that you're using an up to date version of Mono.Cecil where this deprecated type has been removed.

Please have a look at the migration page on Cecil's wiki to know how to convert code for Cecil 0.9. You'll see that you just have to change this line to read:

var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
Jb Evain
  • 17,319
  • 2
  • 67
  • 67
  • thank you very much. It worked for me. Also till the time i did not get the answer i downloaded the source code of a working project from the site. It contained the usage of "AssemblyFactory" just as i had mentioned. That project contained an assembly lib.dll which i took and used in my project. – samar Nov 17 '11 at 11:09
  • Whoa, that change broke *[Mono.Cecil, The Most Powerful Tool You've Ever Heard Of](http://www.codeproject.com/Articles/17690/Mono-Cecil-The-Most-Powerful-Tool-You-ve-Ever-Hear)* (at [The Code Project](http://en.wikipedia.org/wiki/The_Code_Project)). – Peter Mortensen Sep 17 '13 at 13:40
  • 1
    Also, type *CilWorker* was renamed to *ILProcessor* (*Mono.Cecil.Cil.ILProcessor*), and a property to get it, *CilWorker*, was renamed to *GetILProcessor* (*Mono.Cecil.Cil.MethodBody.GetILProcessor*, for instance, *.Body.GetILProcessor* on a *MethodDefinition*). A code example from the [Cecil FAQ](http://www.mono-project.com/Cecil:FAQ) uses the old ones - update? – Peter Mortensen Sep 18 '13 at 14:33