none
Change the name of an assembly at runtime RRS feed

  • Question

  • Hey all

    I was wondering if it is possible to load an assembly into memory at runtime, change the name of the assembly, and save it out to disk with its new name?

    Would really appreciate any help on this!

    Thanks.

    Monday, October 17, 2011 1:27 AM

Answers

  • OK. You want to change the main module name inside the assembly. An assembly is a file containing module(s) and metadata, one of the module is the main module and rest are child modules.

    I believe it is not possible to change a module name without recompiling the module. This is because you need to save the module name back to assembly, which would require compiling the code to IL (because assemblies contain IL). Also the Module class can only GET (or read) properties in a module and not write them back.


    Click the 'Vote as Helpful' arrow if this post was helpful.
    • Marked as answer by tompsonn Tuesday, October 18, 2011 8:06 AM
    Tuesday, October 18, 2011 6:28 AM

All replies

  • If you want to change the name, why don't you just rename the assembly file? Can you elaborate what you are trying to do?
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Monday, October 17, 2011 4:55 PM
  • If you rename the file itself, this does not change the actual assembly name used internally by the CLR, correct?

    For example, if I compile a class library with the assembly name (in visual studio) set to "MyAssembly.SomeLibrary", it will be output as MyAssembly.SomeLibrary.dll.

    If I rename that file to MyAssembly.SomeLibraryWithANewName.dll, the CLR will still treat the assembly's ACTUAL name as MyAssembly.SomeLibrary.

    Is this correct?

    They aren't strong named assemblies.

    Tuesday, October 18, 2011 12:31 AM
  • OK. You want to change the main module name inside the assembly. An assembly is a file containing module(s) and metadata, one of the module is the main module and rest are child modules.

    I believe it is not possible to change a module name without recompiling the module. This is because you need to save the module name back to assembly, which would require compiling the code to IL (because assemblies contain IL). Also the Module class can only GET (or read) properties in a module and not write them back.


    Click the 'Vote as Helpful' arrow if this post was helpful.
    • Marked as answer by tompsonn Tuesday, October 18, 2011 8:06 AM
    Tuesday, October 18, 2011 6:28 AM
  • So basically, it's not possibly to do on the fly in code...

    That's alright, just wondering if it was!

    Thanks for your help!

    Tuesday, October 18, 2011 6:35 AM
  • Please up vote the helpful posts and "Mark as Answer" the post that answers the question. This will close the topic and help other users.
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Tuesday, October 18, 2011 6:53 AM