Server Activated ServicedComponent and Config Files
Yes, it is possible to specify a per-component application config when using a ServicedComponent with activation type set to Server Application. By default all Server Applications are sharing dllhost.exe.config located in %windir%\system32. But there are cases when you need to have different configs for different Server Apps. For instance, an important scenario is to have component A using version 1.0 of .Net Framework and component B using version 1.1.
This can be achieved by setting the Application Root Directory for that component to point to a directory where you have two files: application.manifest and application.config. The manifest can be as simple as:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>
The application.config will be your normal app config where you can put your specific settings for your component.
[Originally posted Oct 13, 2003]
Comments
- Anonymous
December 28, 2003
Hi Florin, this feature works only for winxp and win2k3. Do you know if exists something similar under win2k ?. Thanks. - Anonymous
January 02, 2004
Paul - Unfortunately Win2K doesn't support per app config files because Win2K doesn't have Application Root Directory. - Anonymous
April 11, 2004
Hi folrin, i've been trying this for some time and it just won't work, i have winXP prof, do i need to install service pack 2 for this to work? thanks - Anonymous
April 13, 2004
The comment has been removed - Anonymous
May 17, 2004
Under W2k3, the files can be renamed as <ServerApplicationName>.manifest and <ServerApplicationName>.config. Unfortunately this solution doesn't work under windows xp - Anonymous
May 30, 2004
All out-of-process COM applications by default are executed using the %SystemRoot%System32dllhost.exe surrogate process. What this used to mean that calling System.Configuration.ConfigurationSettings.AppSettings[ - Anonymous
August 03, 2004
Hi i have similar problems
I'm developing mmc SNAP-in in vb6 using snapin designer,
snain needs to interact with database ,
database interaction code is written in vb.net,
to use that .net assembly i register it for COM interoperability, And it successfully run in vb form project , And all config file settings successfdully obtained when runnin vb6 project exe.
Now i use that same vb.net assembly in snapin by registering for COM interoperability.
( Snapin creates .ocx file)
Now when i load snapin in mmc, it woun't find any config file, even though i renamed app.config as dllhost.exe.config
I'm using win2k
Any type of help highly appreciated - Anonymous
April 25, 2005
Hi there do you have any idea how to overcome the problem under the W2K environment any idea will be highly appreciated THNAKS - Anonymous
April 27, 2005
For win2k I copied a code fragment that was suggested of ADVANCED DOTNET list.(I'm not sure from whom, and modified 4 lines of code)
I post the source code because so maybe it can be useful to others. Basically all you have to do is inherit for ServicedComponentEx.
Good luck!
[AttributeUsage(AttributeTargets.Class)]
public class ServicedComponentExProxyAttribute : ProxyAttribute, ICustomFactory
{
private ProxyAttribute _base;
private Type currentType;
static AppDomain appDomain = null;
public ServicedComponentExProxyAttribute()
{
_base = (ProxyAttribute)typeof(ServicedComponent).GetCustomAttributes(typeof(ProxyAttribute),false)[0];
}
public override MarshalByRefObject CreateInstance(Type serverType)
{
return _base.CreateInstance(serverType);
}
public override RealProxy CreateProxy(ObjRef objRef,Type serverType,object serverObject,Context serverContext)
{
return _base.CreateProxy(objRef,serverType,serverObject,serverContext);
}
Assembly ResolveHelper(object o, ResolveEventArgs rargs)
{
if ( currentType.Assembly.FullName == rargs.Name )
{
return Assembly.LoadFrom(currentType.Assembly.Location);
}
else
{
return null;
}
}
MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
{
if ( AppDomain.CurrentDomain.FriendlyName == "myappdomain" )
{
return ((ICustomFactory)_base).CreateInstance(serverType);
}
else
{
if ( appDomain == null )
{
System.AppDomainSetup appDomainSetup = new AppDomainSetup();
appDomainSetup.ApplicationBase =
Path.Combine(Path.GetPathRoot(serverType.Assembly.Location), Path.GetDirectoryName(serverType.Assembly.Location));
appDomainSetup.ApplicationName = "complus";
appDomainSetup.ConfigurationFile = serverType.Assembly.GetName().Name + ".exe.config";
appDomain = AppDomain.CreateDomain("myappdomain",null,appDomainSetup);
}
ResolveEventHandler reh = new ResolveEventHandler(this.ResolveHelper);
currentType = serverType;
AppDomain.CurrentDomain.AssemblyResolve += reh;
MarshalByRefObject mbr = (MarshalByRefObject)appDomain.CreateInstanceFromAndUnwrap(serverType.Assembly.Location,serverType.FullName);
AppDomain.CurrentDomain.AssemblyResolve -= reh;
currentType = null;
return mbr;
}
}
}
[ServicedComponentExProxyAttribute]
public class ServicedComponentEx : ServicedComponent
{
public ServicedComponentEx()
{}
} - Anonymous
July 26, 2005
From http://blogs.msdn.com/florinlazar/archive/2003/12/04/41369.aspx:
setting the Application Root Directory... - Anonymous
August 02, 2005
The comment has been removed - Anonymous
August 17, 2005
Or you could just call AppDomain.CurrentDomain.SetData("APP_CON- FIG_FILE", settingsFilePath);
... - Anonymous
August 28, 2006
I spent far too much time on Friday trying to make log4net work in a COM+ application. Someone else had