Regarding the usage of a config file for a dll:
Currently, the config file is really bound to the exe file. I mean that it
should have the same name and must normally be located in the exe file
directory.
Now, if you want to dedicate a given config file to a dll (and not share the
one of the exe file which initially loaded your dll), you have to create a
new application domain and load the dll in this application domain. This
will give you a chance to specify the config file the application domain
will use.
However, you should note that classes that will be referenced on the second
appdomain from the main appdomain should derive from "MarshalByRefObject"
and they should override the "InitializeLifetimeService" if you plan to have
a long living instance (eg more than 3-4 minutes) referenced from the main
appdomain.
Hope this help,
José
Here is a snippet of how to load a dll in another domain:
//
// Need to isolate the assembly in a new AppDomain in order to be able to
use a customed
// config file [.dll.config]
//
//create the config settings object
AppDomainSetup setup = new AppDomainSetup();
//work out what the config file name and app base are
FileInfo fileInfo = new
FileInfo(Assembly.GetExecutingAssembly().Location) ;
string appBase = fileInfo.DirectoryName;
string configFile = fileInfo.Name + ".config";
//set the app base and the config file
setup.ApplicationBase = appBase;
setup.ConfigurationFile = configFile;
//create the domain
gAppDomain = AppDomain.CreateDomain ("ExportedView: " +
Guid.NewGuid().ToString(), null, setup);
//create the type inside the domain, and get the interface to it
// also define an assembly resolver routine in case the CLR cannot find
our assemblies.
AppDomain.CurrentDomain.AssemblyResolve+=new ResolveEventHandler(
this.MyResolveHandler);
Object o = gAppDomain.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName,
typeof(UFSStatusAccessDomain).FullName);
gUFSStatusAccessDomain = (UFSStatusProvider.UFSStatusAccessDomain)o;
// call the init on the other AppDomain
return gUFSStatusAccessDomain.Init(nTestLevel, out strErrDescr);
.......
//-----------------------------------------------------------------------------------------
/// <summary>
/// This method is used to provide assembly location resolver. It is
called on event as needed by the CLR.
/// Refer to document related to AppDomain.CurrentDomain.AssemblyResolve
/// </summary>
private Assembly MyResolveHandler(object sender,ResolveEventArgs e)
{
string[] file = e.Name.Split( ',' );
string strDir =
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().Location);
Assembly a = Assembly.LoadFrom( strDir + @"\" + file[0] + ".dll" );
return a;
}
"Suresh Gladstone" <su*********@yahoo.com> wrote in message
news:3a****************************@phx.gbl...
Hi,
This is a bit with versioning and installation of
the .NET dlls. I want to perform the following, [THIS IS
WITH REFERENCE TO WINDOWS APPLICATION]
1. A third party application will be invoking my .NET dll
through COM interop . For this I have used Regasm and
registered the assembly in the registry with CODEBASE
option.
eg: regasm myDll.dll
/tlb:myDll.tlb /codebase
2.The main dll which is invoked from the third party
application has some other .NET dll references.
These .NET references are common dlls used by many other
similar main dlls. The situation is we had placed this
common dlls in the GAC and it worked fine through
reference.Now we have a business decision to move these
common dll's to a local directory in the users machine
and refer it from there. I have written a Configuration
file and set the <codeBase ...> to point to the
directory. But it is not working. Can anyone send me a
sample config file how it should be. The point of concern
here is , the configuration file should be created for
the Dll and not the Exe.
3. Process Eg:
i. I have a third party application say A ,
ii. I have a set of main assemblies say B,C,D each of
which will be independently invoked by the third party
application A
iii. I have a set of common .NET dll libraries say X,Y,Z
these will be used by the main assemblies B,C and D
Process
The application A will invoke main assembly B (which is
registered in the registry with codebase option) . I have
placed assembly B in a directory say "c:\MainDlls"
The assembly B references X,Y,Z . I want to place these
X,Y,Z dlls in a common directory (not in GAC)
say "C:\CommonDlls" . The other main assemblies C and D
will also use these common libraries from the same
directory.
|---------X
A --------------->B|---------Y
(Third party |---------Z
application)
I have the following question
1.How should be the config file written in this case.Its
for a .NET dll (not .NET exe)
2.Where should the config file be placed. Since its a
third party invokingapplication, not sure where to place
the config file.
Any help will be really appreciated.
Regards,
Suresh Gladstone