.NETGURU
config file for DLL
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.interop.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Alex K. (VIP)
I define a few constants in a C# DLL. I'd like to be able to store them
externally instead of hard-coding them in the DLL's source. Is there any kind
of DLL-level configuration file that I can read from my DLL?

Thank you.
Reply to this message...
 
    
Richard K Bethell
"Alex K." <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

I have a similar problem. I have a regasm registered .NET dll that I am
trying to call from asp pages. It looks like I cannot use the web.config
file that the application's aspx pages would use. Is there a way to use a
configuration file in some way or another, to return static properties?

Richard

Reply to this message...
 
    
Thomas S. Trias (VIP)
I ran into a similar issue using COM interop from ASP (not ASP.NET,
obviously) to call WebService proxy objects written using WSE 2.0; I couldn't
use WSE Policy because I couldn't reference the config unless I wanted to
deploy inetinfo.exe.config and dllhost.exe.config files to the web server.

Unfortunately, given no access to the base parsing mechanisms for the policy
config, I had to home-grow my own solution via code; my classes now read up
xml files (either in the deployment directory, current working directory, or
specified by the object consumer) in order to set their configuration. I
suppose you can do the same sort of thing, you just don't get it for free.

Thomas S. Trias
Senior Developer
Afni Insurance Services
http://www.afniinc.com/

Reply to this message...
 
    
Alex K. (VIP)
Thank you Thomas for your advice.

I have come to similar home-grown solution: I am using my own XML config
file for DLL.
It seems that DLL has no current run-time folder, therefore, class
constructor defined in the DLL receives current path from client, to figure
out where to look for the config file.

To pass this parameter I am using

Server.MapPath(".") + "\\"

for ASP clients, and

Environment.CurrentDirectory

for C# EXE clients.

Luckily, all my clients are located in the same directory with DLL so I
don't need multiple config files.
So, it is kind of tricky. It would be much easier if I can get original DLL
folder from inside the DLL.

Alex.

"Thomas S. Trias" wrote:

[Original message clipped]

Reply to this message...
 
    
SA
You can use

System.Reflection.Assembly.GetExecutingAssembly().CodeBase

to get the full path of the currently executing assembly (DLL file). You
will have to strip the filename from the CodeBase property, but
alternatively, it makes it easy to just append ".config" to it.

HTH

--

Sven

"Alex K." <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Alex K. (VIP)
Thanks Sven!!!
It works! The only thing I need to add is to convert CodeBase to URI
AbsolutePath or LocalPath (both work fine):

string s = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
s += ".config";

Uri uu = new Uri(s);
strFileName = uu.LocalPath; //uu.AbsolutePath - also works;

Alex

"SA" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Environment
System.Reflection.Assembly
System.Uri
System.Web.Services.WebService




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification