locked
C# Dynamic dll system problem RRS feed

  • Question

  • Hi, I have an application that loads dlls dynamically. The application and the
    dlls use a Functions.dll that can be a diferent version for the application an
    for each dll, but in execution the application and the dlls all use the same
    dll version (the one used by the EXE) and share the static variables...
    How can i force them to use their own Functions.dll(n-version)?

    -Details:
    *I tried loading the dlls by "Assembly dll = Assembly.LoadFile("
    and by "Assembly dll=domaindll.Load("
    *In Functions.dll, al the methods and objects are Static
    *I use Functions.dll "statically" by referencing it in all cases not dynamically
    *The dlls and Functions.dll are developed in C# too
    -Estructure:
    Application:
        Application.EXE
        Functions.dll(version 1.2)
        DLLS:
            EXAMPLEDLL1:
                EXAMPLEDLL1.DLL
                Functions.dll(version 1.1)
            EXAMPLEDLL2:
                EXAMPLEDLL2.DLL
                Functions.dll(version 1.0)
            EXAMPLEDLL3:
                EXAMPLEDLL3.DLL
                Functions.dll(version 1.2)
    Thursday, June 4, 2009 11:29 AM

Answers

  • Hello,

    Please try to give each version of the the assembly (Functions.dll in this case) a strong name and install them in the GAC (Global Assembly Cache), and then, we could load an assembly of a specific version dynamically. Just like 1987raymond suggested.

    To give an assembly a strong name:
     1. right click the project name and choose Properties
     2. choose Signing tab on the left
     3. check "Sign the assembly" check box on the right
     4. Click the dropdown list and choose <New...> to create a new key file
     5. give it a name like MyKeyFile in the Key file name box, if you will, just input the password, or, uncheck the "Protect my key file with a password" checkbox.
     6. Build the project again.
    Or, we could use the Strong Name Tool (SN.exe) to achieve the same goal.

    To Install the assembly to the GAC, please refer to this article, it contains the detailed steps to do that:
    http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

    Please have a try and tell me the result!
    Best regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Friday, June 12, 2009 6:40 AM
    Wednesday, June 10, 2009 11:55 AM

All replies

  • hey,ase69_s, maybe you can let it a go as the follows:

     // You must supply a valid fully qualified assembly name.           
            Assembly SampleAssembly = Assembly.Load
        ("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
            // Display all the types contained in the specified assembly.
    foreach (Type oType in SampleAssembly.GetTypes()) {
                Console.WriteLine(oType.Name);

    努力着就不会放弃!.net技术交流群 33083877http://hi.baidu.com/1987raymond
    • Proposed as answer by liurong luo Thursday, June 11, 2009 1:03 AM
    Thursday, June 4, 2009 11:41 AM
  • The CLR will load the different versions of the DLL as long as their identity (name, version, strongname) differs and you don't have any binding redirects or publisher policy in place saying that a newer version should replace an older. Is the Functions assembly strong named?


    Mattias, C# MVP
    Thursday, June 4, 2009 11:59 AM
  • Hello,

    Please try to give each version of the the assembly (Functions.dll in this case) a strong name and install them in the GAC (Global Assembly Cache), and then, we could load an assembly of a specific version dynamically. Just like 1987raymond suggested.

    To give an assembly a strong name:
     1. right click the project name and choose Properties
     2. choose Signing tab on the left
     3. check "Sign the assembly" check box on the right
     4. Click the dropdown list and choose <New...> to create a new key file
     5. give it a name like MyKeyFile in the Key file name box, if you will, just input the password, or, uncheck the "Protect my key file with a password" checkbox.
     6. Build the project again.
    Or, we could use the Strong Name Tool (SN.exe) to achieve the same goal.

    To Install the assembly to the GAC, please refer to this article, it contains the detailed steps to do that:
    http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

    Please have a try and tell me the result!
    Best regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Friday, June 12, 2009 6:40 AM
    Wednesday, June 10, 2009 11:55 AM