Best way to have config file for Assembly? 
Author Message
 Best way to have config file for Assembly?

Hi,
I'm trying to come up with a solution to have a configuration file for an
Assembly.
I know hoge.dll.config doesn't work like it does for .exe file. When I try
to use
Assembly.ExecutingAssembly().Location and if the Assembly is registered in
GAC,
it returns something like C:\winnt\assembly\hoge\23009_9879\hoge.dll, which
is not
acceptable. I tried CodeBase property, but result is still the same.

I guess if the Assembly is not registered in GAC, it will return the correct
path to the Assembly.

What would be the best practice? Should the host app pass the path to the
configuration
file I created? I know it may work, but I don't really like the solution
because I want Assembly
itself to know where the configuration file is without hardcoding.

Any help is appreciated.



Wed, 13 Apr 2005 06:14:18 GMT  
 Best way to have config file for Assembly?
I am using library specific confguration files, by checking the in-file in
the GAC directory for the location from where the assembly was registered.
That's the only approach I found to work for assemblies in the GAC.

Let me know if you need a code example.

HTH,
Christoph Schittko


Quote:
> Hi,
> I'm trying to come up with a solution to have a configuration file for an
> Assembly.
> I know hoge.dll.config doesn't work like it does for .exe file. When I try
> to use
> Assembly.ExecutingAssembly().Location and if the Assembly is registered in
> GAC,
> it returns something like C:\winnt\assembly\hoge\23009_9879\hoge.dll,
which
> is not
> acceptable. I tried CodeBase property, but result is still the same.

> I guess if the Assembly is not registered in GAC, it will return the
correct
> path to the Assembly.

> What would be the best practice? Should the host app pass the path to the
> configuration
> file I created? I know it may work, but I don't really like the solution
> because I want Assembly
> itself to know where the configuration file is without hardcoding.

> Any help is appreciated.



Wed, 13 Apr 2005 06:33:24 GMT  
 Best way to have config file for Assembly?
Here are a few lines to get to the path where your library assembly is
located.

string s = "";
System.Reflection.Assembly executingAssembly =
System.Reflection.Assembly.GetExecutingAssembly();
if( ( true == executingAssembly.GlobalAssemblyCache )
{
  INIReader iniReader = new INIReader(

  System.IO.Path.GetDirectoryName(executingAssembly.Location),
    "__AssemblyInfo__.ini" ) );
  s = System.IO.Path.GetDirectoryName( iniReader.ReadString("AssemblyInfo",
"URL", "") );

Quote:
}

else
{
  s =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly().CodeBase);

Quote:
}


Once you have the path you can read it with the method of your choice. One
of the DevelopMentor guys has an example class to read an assembly
configuration file. You can also parse the config file by hand or with Xml
Serialization.

I found INIReader class somewhere on the internet, but it's just a wrapper
aroud the Win32 API GetPrivateProfile methods. I'm sure you can find it on
Google.

HTH,
Christoph Schittko


Quote:
> Hi,
> Thank you very much for your reply.
> I would really like to have a look at your code example.
> Could you point me where I can get it?

> Thanks


message

> > I am using library specific confguration files, by checking the in-file
in
> > the GAC directory for the location from where the assembly was
registered.
> > That's the only approach I found to work for assemblies in the GAC.

> > Let me know if you need a code example.

> > HTH,
> > Christoph Schittko



> > > Hi,
> > > I'm trying to come up with a solution to have a configuration file for
> an
> > > Assembly.
> > > I know hoge.dll.config doesn't work like it does for .exe file. When I
> try
> > > to use
> > > Assembly.ExecutingAssembly().Location and if the Assembly is
registered
> in
> > > GAC,
> > > it returns something like C:\winnt\assembly\hoge\23009_9879\hoge.dll,
> > which
> > > is not
> > > acceptable. I tried CodeBase property, but result is still the same.

> > > I guess if the Assembly is not registered in GAC, it will return the
> > correct
> > > path to the Assembly.

> > > What would be the best practice? Should the host app pass the path to
> the
> > > configuration
> > > file I created? I know it may work, but I don't really like the
solution
> > > because I want Assembly
> > > itself to know where the configuration file is without hardcoding.

> > > Any help is appreciated.



Wed, 13 Apr 2005 07:05:27 GMT  
 Best way to have config file for Assembly?
Hi,
Thank you very much for your reply.
I would really like to have a look at your code example.
Could you point me where I can get it?

Thanks


Quote:
> I am using library specific confguration files, by checking the in-file in
> the GAC directory for the location from where the assembly was registered.
> That's the only approach I found to work for assemblies in the GAC.

> Let me know if you need a code example.

> HTH,
> Christoph Schittko



> > Hi,
> > I'm trying to come up with a solution to have a configuration file for
an
> > Assembly.
> > I know hoge.dll.config doesn't work like it does for .exe file. When I
try
> > to use
> > Assembly.ExecutingAssembly().Location and if the Assembly is registered
in
> > GAC,
> > it returns something like C:\winnt\assembly\hoge\23009_9879\hoge.dll,
> which
> > is not
> > acceptable. I tried CodeBase property, but result is still the same.

> > I guess if the Assembly is not registered in GAC, it will return the
> correct
> > path to the Assembly.

> > What would be the best practice? Should the host app pass the path to
the
> > configuration
> > file I created? I know it may work, but I don't really like the solution
> > because I want Assembly
> > itself to know where the configuration file is without hardcoding.

> > Any help is appreciated.



Wed, 13 Apr 2005 06:59:38 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. are there better ways to read config file?

2. Still having problems with config files...

3. Can you access .config files in DLL assemblies?

4. Can we modify assembly.exe.config file

5. Config files: best to use struct when reading in data

6. Updating the security.config file in the CONFIG directory

7. Assemblies element in web.config

8. Help with ideas, best ways etc...

9. Good ways to obfuscate/mangle strings?

10. Any good ways to trace memory leaks?

11. just having one instance of a assembly..

12. having hard time getting good SERVICE these days

 

 
Powered by phpBB® Forum Software