Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

App.config Problem

Status
Not open for further replies.

mary0125

Programmer
Feb 10, 2003
3
0
0
US
I am having a problem accessing the app.config. I have a VB.net project that is just a class without a form. I have a app.config added to the project. When I build the project, the app.exe.config does not get added to the Bin directory, and when I access the config file, I get nothing.

Though when I add a form to the project and add the config file to the project and build it, the app.exe.config file gets added to the bin directory and I can access it.

Any help would be appreciated.

Thanks
 
The config file will be associated with the executable that will call the dll.
 
We are using the DLL's and calling them from a VB6 application. So what you are saying is that App.config files can be used from the exe and not from DLL's. In that case, we will change the app to get the values from an XML file that has the same information as the config file.

Thanks
 
The App.config information can be accessed from the DLL, but they access the information associated with the calling executable. The best the to do would be to set these variables via properties or function parameters. This allows the same dll to be called from different applications that may want to pass it different parameters. This also helps by only requiring you to set something in one place.
Assume that your application has 5 DLL's that access a database. You would have to set the connection string in all 5 config files instead of just the config file of the one executable.
Since you are calling this from a VB6 app, I would put these configuration items in an .ini file or the registry and pass them to the DLL when it is called.
 
App.config cannot be accessed directly from a dll.

The executeable can read in the data and pass the results to the dll but the dll cannot read app.config directly.

Craig

PS This is all in Help.....
 
Craig,
Actually your statement isn't completely accurate. While it is true that the config file is associate with the calling exe, the data can be accessed directly from a called dll. I have several instances where I have used system.configuration.configurationsettings.appsettings("SomeVariable") directly in a dll without passing any parameters. This accesses the data from the app.config of the calling exe.
I do agree, however, that it is a better practice to actually pass the parameters to the dll to make it obvious to someone writing a calling program exactly what is required by the dll.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top