How to access MySettings from a DLL?


R

Rich

Hi,

I have a vb.net solution created in Studio 2008 running on .Net 2.0.

The solution contains 2 projects, a main Windows app and a business logic
project that compiles to a separate DLL.

In the main app I have used MyProject.Settings to setup connection strings
etc... but I can't access these config keys from the business logic project
(DLL).

Does anyone know how to get my business logic project to 'see' the
MyProject.Settings keys from the main application?

--

Rich

http://www.badangling.com
....talking pollocks since 1996
 
Ad

Advertisements

S

Steve Gerrard

Rich said:
Hi,

I have a vb.net solution created in Studio 2008 running on .Net 2.0.

The solution contains 2 projects, a main Windows app and a business
logic project that compiles to a separate DLL.

In the main app I have used MyProject.Settings to setup connection
strings etc... but I can't access these config keys from the business
logic project (DLL).

Does anyone know how to get my business logic project to 'see' the
MyProject.Settings keys from the main application?

Not supposed to. :) A dll is meant to be able to work with different apps.

A dll can have its own settings, but I found that can get muddled pretty easily,
as the latest version of the dll settings won't automatically get copied to
projects using it, as happens with the dll itself.

A more general solution is probably to setup a Configure method in the dll, and
pass it along the values of interest from whatever app happens to be calling it.
Or just make it part of the constructor for the main class, and pass in the
values when you use New.
 
R

Rich

Steve Gerrard said:
Not supposed to. :) A dll is meant to be able to work with different apps.

I agree, but the DLL is a class library project that forms by business logic
and data access layer. It uses connection strings that are also used by the
main app project that uses the DLL. At the moment I end up having the
connection string in the app.config of the main application, and also in the
app.config of the class library (DLL) project.

The DLL that my class library project generates is only used by the one
application so it isn't designed to work with different apps ;-)
A dll can have its own settings, but I found that can get muddled pretty
easily, as the latest version of the dll settings won't automatically get
copied to projects using it, as happens with the dll itself.

A more general solution is probably to setup a Configure method in the
dll, and pass it along the values of interest from whatever app happens to
be calling it. Or just make it part of the constructor for the main class,
and pass in the values when you use New.

I did consider that, but I'd rather the DLL just read the same set of config
values as the main app directly.

--

Rich

http://www.badangling.com
....talking pollocks since 1996
 
K

kevininstructor

I have a solution if interested send me an email at
(e-mail address removed)

In short I don't use the standard app.config but instead replace it with an
XML file which "knows" the calling application via reflection and reads this
applications xml configuration file. I needed this for my "unhandled
expection handler" DLL and it works great.
 
I

Inictus

Hi,

I have a vb.net solution created in Studio 2008 running on .Net 2.0.

The solution contains 2 projects, a main Windows app and a business logic
project that compiles to a separate DLL.

In the main app I have used MyProject.Settings to setup connection strings
etc... but I can't access these config keys from the business logic project
(DLL).

Does anyone know how to get my business logic project to 'see' the
MyProject.Settings keys from the main application?

--

Rich

http://www.badangling.com
...talking pollocks since 1996

An alternative to the other suggestions would be to create a new
assembly with a class with shared methods to manage this data. Both
the app and your business logic would have references to this new
assembly. Upon start up, your app could set the appropriate values,
and the DLL would then have access to this data. This assumes that the
calls made to this business logic DLL are in the same thread as the
GUI - you are not multithreading on the other DLL are you?
 
Ad

Advertisements

H

huntco

Hi,

I have a vb.net solution created in Studio 2008 running on .Net 2.0.

The solution contains 2 projects, a main Windows app and a business logic
project that compiles to a separate DLL.

In the main app I have used MyProject.Settings to setup connection strings
etc... but I can't access these config keys from the business logic project
(DLL).

Does anyone know how to get my business logic project to 'see' the
MyProject.Settings keys from the main application?

--

Rich

http://www.badangling.com
...talking pollocks since 1996

Rich,

Hit the same roadblock myself a while back. Finally worked through it
and posted the lessons learned/how I got it working at
http://tracyhunt.blogspot.com/2007/10/configuring-net-dll.html.

Tracy
 
Ad

Advertisements


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