lundi 23 novembre 2015

Get physical file name of inherited class

I'm sorry to have to ask a similar question to one I've already asked and has been answered but I'm stuck here and was hoping that someone could set me on the right path again. (Original question here: Get DLL's file name of inherited class)

I have an abstract class called PluginBase.dll from which various other classes inherit. These are all compiled as different plugins for a server application. Let's look at one of these plugins, called PluginMessaging.dll which has a config file called PluginMessaging.dll.config

The method that reads the config settings is in the base class and looks something as follows:

private void ReadConfig()
{
    _runningDir = System.IO.Path.GetDirectoryName(GetType().Assembly.Location);
    _pluginFile = System.IO.Path.GetFileName(GetType().Assembly.Location);
    _configFile = _pluginFile + ".config";

    // Do stuff here that reads from _configFile
}

The line of code that assigns a value to _pluginFile is what I got from the first time I asked the question (answered by Damien_The_Unbeliever) and it works fine, as long as there is only one instance of the PluginMessaging file and its config file.

What I'm trying to do now is to make two copies of the compiled plugin, let's call them PluginMessaging_A.dll and PluginMessaging_B.dll, each with its own corresponding config file, PluginMessaging_A.dll.config and PluginMessaging_B.dll.config respectively.

The problem I'm having is that, the server application iterates through all *.dll files in its Plugins folder, instantiates each one and calls the above ReadConfig() method for each. When the function is called for PluginMessaging_A.dll everything works as expected and the value of _pluginFile is PluginMessaging_A.dll but when the ReadConfig() function for the second copy of the DLL, PluginMessaging_B.dll is called, for some reason, _pluginFile again resolves to PluginMessaging_A.dll

It would seem as if there is some table in memory that remembers the GetType().Assembly information for PluginMessaging.dll the first time it is instantiated, regardless of what physical name it has on disk and retains that for any subsequent instances of the same DLL, albeit with a different name on disk.





Aucun commentaire:

Enregistrer un commentaire