Reputation: 31221
Currently I have 2 apps, App1 and App2.
App1 has an app.config file where I store the string InstallDir
. I can access this from App1 fine using Properties.Settings.Default.InstallDir
. Which works great, but I need to be able to access this from App2.
I changed the accessibility from Internal
to Public
in VS. When I try to access it from App2 I add a reference to App1 and use using App1;
and App1.Properties.Settings.Default.InstallDir
but it justs returns nothing. It doesn't throw an exception, it just returns a blank string.
Any ideas greatly appreciated.
Upvotes: 2
Views: 3807
Reputation: 2880
Your application will only have loaded one configuration file, if you want to read values from the other file you will need to explicitly load it.
look at Using ConfigurationManager to load config from an arbitrary location for some help with this.
Upvotes: 0
Reputation: 2943
You can only write your own code to switch reading another config file, even you add App2 as a reference it would not magically give you access, read it as a normal file or use ConfigurationManager.OpenMappedExeConfiguration: http://msdn.microsoft.com/en-us/library/ms134269.aspx
Upvotes: 0
Reputation: 62248
If you want to access some (I presume) shared configuration options between 2 projects, create wrapper for the config on the first one (let's say a static
class) and use it from your second project.
Upvotes: 2
Reputation: 1038710
Every application has its own app.config file where it reads configuration from at runtime. You have referenced App1 in App2 which allows you to access the App1.Properties.Settings.Default.InstallDir
variable but at runtime since there's no corresponding value in the app.config of App2 it returns null.
Upvotes: 3