Question

I have a solution with projects: Utilities MainProject

where Utilities is used by MainProject, and MainProject is the main dll that I am using.

I have a app.config for each project. In particular, my Utilities project automatically places its app.config in Utilities\bin\debug\ folder. In my code, I am trying to access it from:

private static Configuration UConfiguration = ConfigurationManager.OpenExeConfiguration(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);

or

private static Configuration UConfiguration = ConfigurationManager.OpenExeConfiguration(typeof(UtilitiesConfiguration).Assembly.Location);

but obviously they both give same null pointer exception error when I am trying to access the configuration.

When I print out the FilePath of the Configuration, it shows it is trying to load this configuration from MainProject\bin\debug where all dlls eventually goes to, but the Utilities' app.config apparently didn't get copied over.

What is the best approach to fix this issue?

Was it helpful?

Solution

The main application.config is where you application will read the config from. the other configs are not looked at.

What are you trying to do and maybe there is a better solution using a class made up of ConfigurationElements and a custom Section

if you make the utilities application read from the utilities.config file you will cause confusion later on when another developer tries to edit the config or needs to debug and they will only look in the main applications config. it is just not a standard from my experieince

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top