Loading resources from satellite assemblies of reflection loaded assemblies..

Discussion in 'Microsoft C# .NET' started by npthomson@gmail.com, Nov 23, 2006.

  1. Guest

    Hi all,

    This could get a bit complicated but I'll try to be as clear as
    possible. I've written an application that discovers plugins at
    runtime using reflection from a subdirectory of the application, eg:

    In the directory the application is installed to:

    \application.exe
    \plugins\plugin1.dll
    \plugins\plugin2.dll

    I've successfully generated satellite assemblies for the main
    application, these appear as (for example):

    \en\application.resource.dll
    \fr\application.resource.dll

    All is good so far. The plugins also have resources that need to be
    localized, I expected their satellite assemblies to be required under:

    \plugins\en\plugin1.resource.dll
    \plugins\en\plugin2.resource.dll
    \plugins\fr\plugin1.resource.dll
    \plugins\fr\plugin2.resource.dll

    However I find that my the ResourceManager class is trying to load them
    from the same location as the application satellite assemblies:

    \en\plugin1.resource.dll
    \en\plugin2.resource.dll
    \fr\plugin1.resource.dll
    \fr\plugin2.resource.dll

    I include some xml embedded in each plugin assembly so that the
    application knows what classes it can create, the following is a
    simplification of the loading code (this stuff is in the application
    assembly).

    FileName = "\plugins\plugin1.dll"; // obviously this isn't hard coded
    in the app.
    _pluginAssembly = Assembly.LoadFile(FileName);

    At this point the XML is loaded, part of this is the name of the
    resources that your supposed to pass to the constructor of
    ResourceManager. For example assuming the plugin has the namespace
    application.plugin1 and the file is resource.resx the xml would contain
    application.plugin.resource.

    We then create the ResourceManager:

    resName = "application.plugin1.resource";
    ResourceManager rm = new ResourceManager(resName, _pluginAssembly);

    And ask for a string

    CultureInfo ci = new CultureInfo("fr");
    String str = rm.GetString("string", ci);

    this returns the string that is in plugin assembly (plugin1.dll) rather
    than the satellite assembly no mater which culture I ask for. Using
    SysInternal's filemon I see the application looking for
    \fr\plugin1.resource.dll then \fr\plugin1.resource.exe. Obviously the
    same occurs for dialogs, I assume
    System.ComponentModel.ComponentResourceManager (used by default be the
    IDE when you make a localizable dialog) is using the same rules as
    ResourceManager.

    Is there any way of getting resource from a subdirectory of \plugins\
    rather then off of the base directory for those plugin resources?

    Thanks

    Nick
     
    , Nov 23, 2006
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sacha
    Replies:
    1
    Views:
    177
    Bret Mulvey
    Oct 28, 2003
  2. Guest
    Replies:
    2
    Views:
    236
    Guest
    Apr 3, 2006
  3. Nader
    Replies:
    2
    Views:
    182
    D. Yates
    Mar 15, 2007
  4. Michel

    C# loading satellite assemblies

    Michel, Nov 21, 2007, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    219
    Michel
    Nov 21, 2007
  5. Matze

    Assemblies and satellite assemblies

    Matze, Jun 18, 2008, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    234
    Matze
    Jun 18, 2008
Loading...

Share This Page