c# run-time load of assembly problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • millevlada
    New Member
    • Mar 2008
    • 3

    c# run-time load of assembly problem

    Hi all.

    Here is description of my run-time assembly loading problem:

    I would like to have winService hosting .Net remoting objects.
    But, it should work in sort of pluginable way, so during starting of winService it would look into certain folder configured with App.config and dynamically load assemblies from deployed dll-s. Registering of remote objects would be done in some AddonXXX: IAddonXXX class that is defined in each dll, and some mutual interface IAddonXXX would be used to identify those addon classes after assembly is loaded in run-time.

    This all sound ok, but now I have encounter following problem.

    Naturally, my plugin dll references some other dlls, and after loading of assembly when addonAssembly.G etExportedTypes is executed I keep getting this error:

    "Could not load file or assembly 'DALXXXModule, Version=1.0.0.0 , Culture=neutral , PublicKeyToken= null' or one of its dependencies. The system cannot find the file specified."

    I tried pretty much all I though it could make a difference.

    System.Reflecti on.Assembly.Loa d
    AppDomain.Curre ntDomain.Load

    even I deployed all referenced dlls and load them in order that first are loaded referenced dlls and plugin dll at the end, but error remains same.

    So, my question is:

    What is correct way to load dll at runtime? And I would prefer if dll should not be stored in GAC.

    So, somehow I suppose that this should be common thing to do and there is probably right way to do this... Can anybody help me? Tnx.
  • millevlada
    New Member
    • Mar 2008
    • 3

    #2
    here is also code:
    ...
    System.Reflecti on.Assembly addonAssembly;
    XmlDocument xmlConfig;

    foreach (string fileName in Directory.GetFi les(FolderName, "*PluginConfigu ration.xml"))
    {
    xmlConfig = new XmlDocument();
    xmlConfig.Load( fileName);
    XmlNodeList assemblyIdentit yNodes = xmlConfig.GetEl ementsByTagName ("assemblyIdent ity");

    foreach (XmlNode assemblyIdentit yNode in assemblyIdentit yNodes)
    {
    string dllName = FolderName + "\\" + assemblyIdentit yNode.Attribute s["name"].Value;

    byte[] rawAssembly = IOUtils.LoadFil e(dllName);
    byte[] rawSymbolStore = IOUtils.LoadFil e(dllName.Subst ring(0, dllName.Length - 3) + "pdb");

    addonAssembly = AppDomain.Curre ntDomain.Load(r awAssembly);//, rawSymbolStore) ;

    foreach (System.Type exportedType in addonAssembly.G etExportedTypes ())
    {
    IRemotingBIZMod uleAddon addonInstance;
    try
    {
    addonInstance = (IRemotingBIZMo duleAddon)addon Assembly.Create Instance(export edType.FullName , true);
    }
    catch (Exception ex)
    {
    addonInstance = null;
    }

    if (addonInstance != null)
    {
    addonInstance.I nstall(logWrite r, this);
    }
    }
    }
    }
    ...


    error is raised with addonAssembly.G etExportedTypes ()

    Comment

    • millevlada
      New Member
      • Mar 2008
      • 3

      #3
      Ok, I found solution.

      following config should be added into App.config of winService project

      <runtime>
      <assemblyBindin g xmlns="urn:sche mas-microsoft-com:asm.v1">
      <probing privatePath="Ad donRemoteObject sFolder" />
      </assemblyBinding >
      </runtime>

      all "private paths" that would be used to hold dll-s must be registered through probing element.

      So, this thread can be closed now.

      Comment

      Working...