C# 2.0 ConfigurationManager

Hi There

I am using the new settings features in .NET and I like the way that settings can be strongly typed, such as:

MyExeNamespace.Properties.Settings.Default.FormLocation;

It's pretty cool, .NET creates a Settings class underneath the Properties folder and automatically does the property gets and sets for you.

But say that I have a solution with multiple executables, and one of them is a class library that I am calling from the executable that contains the settings I am after? I can't seem to get a hold of MyExeName.Properties.Settings.Default.FormLocation from the class library, as referencing the main executable would create a circular dependency.

TIA
Bill

[845 byte] By [orekin] at [2007-12-16]
# 1
The settings class that is generated is generated as a internal class, which means that it is only accessible from within the assembly where it is defined, so even if you added a reference from the class library to the main application, this wouldn't work.

Depending on exactly what you want to accomplish, there are a couple of ways that you can get this to work using the designer;

Is the setting that you want to share read-only (application scoped) or is it read-write (user scoped)? If it is user-scoped, would you expect changes made in your class library to be immediately visible to the rest of the application?

If this is a read-only application scoped setting, you should(1) be able to use the suggestion that I outline in http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=00777ce6-c8ad-4726-885b-4bfc0dfd2a3a

(1) Please note that this unfortunately is broken in the beta2 release of Visual Studio 2005.

Best regards,
Johan Stenberg

JohanStenberg at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
Thanks Johan
orekin at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...