App.Config equivalents for dlls?

J

Jamie Owens

Hi everyone,

I have a DLL/assembly I'd like to use in conjuction with an app.config
file. Does anyone know if dlls can have app.configs or something similar?
I ask because one of my assembly classes uses a database, and I'd like to
avoid hard-coding a database connection string. Slapping that information
in a config file that can follow around the DLL would be a help. Of course,
if anyone has other suggestions I'm open to them.

Thanks,

-Jim
 
G

Guest

You don't need to put the App.config file in the Class Library's project.
You put the App.config file in the application that is referencing your class
library's dll.

For example, let's say we have a class library named MyClasses.dll which
uses the app.config file like so:

string connect =
ConfigurationSettings.AppSettings["MyClasses.ConnectionString"];

Now, let's say we have an Windows Application named MyApp.dll which
references MyClasses.dll. It would contain an App.config with an entry such
as:

<appSettings>
<add key="MyClasses.ConnectionString" value="Connection string goes
here" />
</appSettings>
</appSettings>

From what I gather from the problem, this should probably be the desired
solution.

Hope that helps.
 
W

William Stacey [MVP]

Just use an xml file and serialize/deserialize it using XmlSerializer as
needed. You can call it what every you want. If your config is "static"
and does not need to change, your could also add it to the project as an
embedded resource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top