An issue with loadaing assembly using reflection RRS feed

  • Question

  • Helo Friends,

    I am using VS2008 with C# to develop my application. In my application on one form there is a dropdown having two options and depend on the option user selects an assembly gets loaded using reflection. Both the assemblies are actually same assembly but having different location and versions. Now the issue is.

    When user selects Option1 Assembly1 gets loaded and user can invoke methods successfully. Now without restarting the application if user selects option2 assembly2 gets loaded but when user tries to invoke any method it found an exception.

    Exception details: "A procedure imported by 'Aveva.Pdms.Database.Implementation, Version=, Cultu
    re=neutral, PublicKeyToken=17c64733a9775004' could not be loaded.":"

    Code I am using:

    To load assembly I am using:
    Assembly pdmsAssembly = Assembly.LoadFile(Path.Combine(_SMMInstallationPath, @"Aveva.Pdms.Standalone.dll"));
    System.Type pdmsStandAloneInstance = null



    foreach(System.Type type in




    if(0 == String.Compare(type.Name, "PdmsStandalone", true



    pdmsStandAloneInstance = type;






     To invoke the method I am using:



    MethodInfo myMethod = pdmsStandAloneInstance.GetMethod("Start", new Type[] { typeof(System.Collections.Hashtable

    ) });


    new object(), new object[] { m_EnvHashTable });

    On the last line of code where I am invoking the method. I am getting exception.

    Whatever option the user selects first it works well but when selects second option it throws an exception. Please let me know how to ressolve the issue.

    Girish Nehte

    Wednesday, May 11, 2011 7:04 AM


  • Hello,

    this has nothing todo with VSTO.

    I assume that you keep a reference to an Object somewhere in the loaded dll.
    So the Assembly is not unloaded when it's not in use anymore.

    Try to release all Objects you use explicitely, remove all eventhandlers and then try a



    Also ask in a C# Forum / Dynamically load/unload Assemblies at runtime.

    Hope this helps. 

    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Wednesday, May 11, 2011 9:22 AM