none
Assembly.CreateInstance returns null after merging assembly using ILMerge RRS feed

  • Question

  • Hi,

    I am merging two assemblies which are almost same. that is i have an assembly say xyz.dll and i am renaming this to xyzclone.dll. Now iam merging these two(original and renamed assemblies) using ILMerge and output file is xyzclone. Since both the assemblies contain same info i am using the option /allowdup.so all the type names in the output xyzclone is changed. 

    After loading the assembly which i got from ILmerge, the create instance returns null. when i get the exportedtype for that assembly the type exists. But when i use the same type to create instance it is returning null

    Note: I am merging the original and renamed dlls as i couldnt find any other method to change the assmbly name of a dll.

    Please help

    Wednesday, March 26, 2014 7:44 AM

Answers

  • "After loading the assembly which i got from ILmerge, the create instance returns null. when i get the exportedtype for that assembly the type exists. But when i use the same type to create instance it is returning null"

    Try using the type you got from GetExportedTypes with Activator.CreateInstance instead of Assembly.CreateInstance.

    • Marked as answer by Prahalnathan Thursday, March 27, 2014 5:33 AM
    Thursday, March 27, 2014 5:19 AM
    Moderator

All replies

  • "After loading the assembly which i got from ILmerge, the create instance returns null. when i get the exportedtype for that assembly the type exists. But when i use the same type to create instance it is returning null"

    Try using the type you got from GetExportedTypes with Activator.CreateInstance instead of Assembly.CreateInstance.

    • Marked as answer by Prahalnathan Thursday, March 27, 2014 5:33 AM
    Thursday, March 27, 2014 5:19 AM
    Moderator
  • Thanks a lot it helped.

    In my input dll i am using mamy dlls for reference. wont the output file directly copy the code from input ans should i give the path of all the external dlls for sure???

    Thursday, March 27, 2014 5:36 AM
  • I don't know what you are trying to say. If you merge 2 assemblies the resulting assembly will have all the references of those 2 assemblies. The path of referenced dlls is not included in the assembly itself, the referenced dlls need to be in the same directory as the application or in GAC.
    Thursday, March 27, 2014 5:57 AM
    Moderator
  • Mike,

    My doubt is should i definitely provide the referenced dll physical path or is htere a way by which the output dll will copy the reference from the input ilf only.

    Thursday, March 27, 2014 10:44 AM
  • Sorry but I still don't understand what you are trying to say. Where exactly do you want/need to use a physical path to the reference?
    Friday, March 28, 2014 7:40 AM
    Moderator