dllhost.exe.config dilemma fixed, at last – by Microsoft.
A long while back, I wrote about a hack to fix the dllhost.exe.config dilemma of Enterprise Services. That hack no longer works due to changes in the Framework, but the good news is there is an “official” and very easy solution for this now. Unfortunately there is no documentation on this (or at least it’s not easy enough to find that I could locate it) and Google only yields a few hints if you know exactly what you are looking for. So, index this, Google!
What I call the “config dilemma” of Enterprise Services is that because all out-of-process ES applications are executed using the surrogate process provided by %SystemRoot%\System32\dllhost.exe and the runtime is loaded into that process, the default application configuration file is dllhost.exe.config, must reside just next to dllhost.exe (in System32) and is therefore shared across all out-of-process Enterprise Services applications.
That makes using the XML configuration infrastructure for Enterprise Services very unattractive, to say the least.
Now, with COM+ 1.5 (Windows Server 2003) and the .NET Framework 1.1, things did change in a big way.
To use per-application application configuration files, all you have to do is to create an (possibly otherwise empty) “application root directory” for your application in which you place two files: An application.manifest file (that exact name) and an application.config file. Once your application is registered (lazy or using the RegistrationHelper class or through regsvcs.exe), you will have to configure the application’s root directory in the catalog – that can be done either programmatically using the catalog admin API (ApplicationDirectory property) or through the Component Services explorer as shown above.
The picture shows that the example that you can download using the link below is installed at “c:\Development\ES\ConfigTest\ESTest” on my machine and has these two said files sitting right there.
The application.manifest file content is embarrassingly simple
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>
and the application.config isn’t complicated either:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="configBit" value="This rocks!"/>
</appSettings>
</configuration>
These two files, placed into the same directory and properly configured as shown in the above picture, let this class
public class SimpleComponent : ServicedComponent
{
public string GetConfigBit()
{
return ConfigurationSettings.AppSettings["configBit"];
}
}
yield the expected result for GetConfigBit(): “This rocks!”
Download: ESTest.zip