Read From Application Config File In Class Library

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I have read many posts on how you cannot have an app.config file for a class
library, but must read from the main application. This URL, #3, highlights
this point:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005

I cannot simply get an answer as to how to read from the applications main
app.config file. Null exception errors are the result. Does anybody have
actual code that has done this. Also reading from web.config would be great.
 
Hello Derek,
I have read many posts on how you cannot have an app.config file for a
class library, but must read from the main application. This URL, #3,
highlights this point:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005

I cannot simply get an answer as to how to read from the applications
main app.config file. Null exception errors are the result. Does
anybody have actual code that has done this. Also reading from
web.config would be great.

Could you post which values you have stored in which config file, and how
you're reading them from your code. This should be very straightforward.

ConfigurationManager.AppSettings["Name"]
(see: http://msdn.microsoft.com/en-us/lib....configurationmanager.appsettings(VS.80).aspx)

should do the trick.

If you've stored the data in a custom section it would be a little more work.

If youw ant to read from a specific config file you can use

ConfigurationManager.Open***Configuration()
(See: http://msdn.microsoft.com/en-us/lib...tion.configurationmanager_methods(VS.80).aspx)
 
Forget to mention that I am doing this at design time with design time
controls. Cannot get it working. Trying to read from either app.config or
web.config in the main program FROM my class library. Lots of articles on
the web say you can't. If you have specifically done this, I would very much
appreciate knowing how.


Jesse Houwing said:
Hello Derek,
I have read many posts on how you cannot have an app.config file for a
class library, but must read from the main application. This URL, #3,
highlights this point:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005

I cannot simply get an answer as to how to read from the applications
main app.config file. Null exception errors are the result. Does
anybody have actual code that has done this. Also reading from
web.config would be great.

Could you post which values you have stored in which config file, and how
you're reading them from your code. This should be very straightforward.

ConfigurationManager.AppSettings["Name"]
(see:
http://msdn.microsoft.com/en-us/lib....configurationmanager.appsettings(VS.80).aspx)

should do the trick.

If you've stored the data in a custom section it would be a little more
work.

If youw ant to read from a specific config file you can use

ConfigurationManager.Open***Configuration()
(See:
http://msdn.microsoft.com/en-us/lib...tion.configurationmanager_methods(VS.80).aspx)
 
Hello Derek,
Forget to mention that I am doing this at design time with design time
controls. Cannot get it working. Trying to read from either app.config
or web.config in the main program FROM my class library. Lots of
articles on the web say you can't. If you have specifically done this,
I would very much appreciate knowing how.

Reading from the config @ design time is indeed not supported. I know that
the guy behind Peter's Data Package used to provide a library that sits inside
Visual Studio that can do this. You might want to check out his producs and
see what they can do for you.

If you wan to acchieve this yourself, you need to install the Visual Studio
SDK and dive into VSIP. It's not pretty if you need to go that way. You could
also have a look at DXCore by DevExpress, I'm not sure, but my guess is that
you could do what you want using their product in an easier way than through
VSIP directly. DevExpress has a very active forum and very good support,
they can probably help you out, or tell you to stop right now ;).

http://www.peterblum.com/
http://www.devexpress.com/

Jesse
Hello Derek,
I have read many posts on how you cannot have an app.config file for
a class library, but must read from the main application. This URL,
#3, highlights this point:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005

I cannot simply get an answer as to how to read from the
applications main app.config file. Null exception errors are the
result. Does anybody have actual code that has done this. Also
reading from web.config would be great.
Could you post which values you have stored in which config file, and
how you're reading them from your code. This should be very
straightforward.

ConfigurationManager.AppSettings["Name"]
(see:
http://msdn.microsoft.com/en-us/library/system.configuration.configur
ationmanager.appsettings%28VS.80%29.aspx)
should do the trick.

If you've stored the data in a custom section it would be a little
more work.

If youw ant to read from a specific config file you can use

ConfigurationManager.Open***Configuration()
(See:
http://msdn.microsoft.com/en-us/library/system.configuration.configur
ationmanager_methods%28VS.80%29.aspx)
 
Back
Top