Suppose there is a singleton class in an assembly named Common. This DLL is used by my main application and a different version could be used by a plugin DLL in a plugins folder.
The distribution looks like this:
\App.exe
\Common.dll (v1)
\Plugins\Plugin.dll
\Plugins\Common.dll (v2)
So code in both App and Plugin are using that singleton class. I’m facing a hard to trace error which makes me think that somehow sometimes that singleton class loses all of its properties’ values and starts to act like it’s a new instance. From the stack trace, this always happens when it is being accessed by the plugin DLL.
EDIT: I just found some stack traces where it was being accessed by App. So cancel the last line of above paragraph.
Both App and Plugin (different VS projects) are compiled and linked with references added to their respective Common DLL versions.
EDIT: Plugin is loaded using Assembly.LoadFrom in the main AppDomain.
EDIT: Common DLL v2 present in Plugins folder also gets loaded dynamically with the Plugin DLL since all DLLs are being loaded from that folder:
foreach( string extensionFile in Directory.GetFiles( ExtensionsDirectory, "*.dll" ) )
Could anyone help what’s going on?
Although it is possible, Microsoft recomends not loading two versions of the same DLL: http://msdn.microsoft.com/en-us/library/dd153782.aspx#avoid_loading_multiple_versions