I'll explain the situation

We have in our solution 6 projects, One is the winform gui APP which has it's own configuration file.

Then there is another project which is the Data Layer and this also has it's own config file containing the connection string which is in the Properties.Settings are of the project. This is new to me so bare with my poor description I also joined the project later on.

The problem is now we are deploying the project only one application config is deployed and it doesn't contain the connection string as its the application config.

It seems the connection string is 'inside' the dll generated by the DataLayer project.

No one here wants to fix the problem as such what we want is a way of accessing the gui's config from any project.

I though of creating a separate class in the gui that reads the config file and returns the settings we want and then referencing this class in the datalayer and getting the connection string this way.

I had a couple of problems, I could not reference the GUI project from the Data Layer as this would 'create a circular dependency'. The projects are in separate namespaces and I could not add the relevant using statement.

I am at a loss as to the best solution right now. Can someone help with this issue


Re: Visual C# General Configuration Files - Winforms .NET 2.0


In the dll you can find the application settings with the System.Configuration namespace. The classes in there will get there information from the application configuration file so you can put your connectionstring in there.

Re: Visual C# General Configuration Files - Winforms .NET 2.0

Friendly Dog

For deployment, you can add the settings from the dll to your main application config file:

1) copy the <section> element under your <configSection>/<sectionGroup> and put it under application configuration file. If your <section> element from dll config is under the same group (ApplicationSettingGroup or UserSettingGroup), you can put the <section> element under existing <sectionGroup> element, otherwise you can copy the whole <sectionGroup> element from dll config to the application config and put it under <configSections> element.

2) copy the child node of <applicationSettings>, which name is usually [type name].Properties, and add it to application <applicationSettings> element.

In this way your dlls can still have their own config files and the deployed config file will contain everything you need. No code change is required.

Re: Visual C# General Configuration Files - Winforms .NET 2.0


Thanks guys that was really simple and totally effective. As suggested added a reference to system.configuration and used the ConfigurationManager........ class.

This as you have said actually reads the app.config of the executable regardless of which project.

Works like a charm thanks very much. I went with the first solution as we actually do not required separate config files for each dll but knowing it is possible is also useful no doubt for larger projects I may be involved with.