On Wednesday, January 24, 2007 3:07 AM jeta wrote:
Hi Dave,
Thanks for your feedback!
With your further feedback, I understand your problem much better now.
Based on my understanding, you wanted to read the modified value in the
[dllname].dll.config, however, you find that it will always report the old
default value. If I still misunderstood you, please feel free to tell me,
thanks.
Yes, I can reproduce this behavior. In the DLL class library, if I modify
the value in [dllname].dll.config, I will always get the old default value.
However, if I modify the value in [dllname].dll.config, the Exe code *can*
read the new modified value without any problem. It seems that they 2 have
different behaviors.
Further research shows that Mr Sexton is right, ApplicationSettingsBase
will always leverage LocalFileSettingsProvider internally to read the
setting, below is the stack trace I got for LocalFileSettingsProvider
initalization during debugging:
System.Configuration.ApplicationSettingsBase.Initializer.get() C#
System.Configuration.ApplicationSettingsBase.CreateSetting({System.Reflectio
n.RuntimePropertyInfo}) C#
System.Configuration.ApplicationSettingsBase.EnsureInitialized() C#
System.Configuration.ApplicationSettingsBase.Properties.get() C#
System.Configuration.SettingsBase.GetPropertyValueByName("testval") C#
System.Configuration.SettingsBase.this[string].get() C#
System.Configuration.ApplicationSettingsBase.GetPropertyValue("testval")
C#
System.Configuration.ApplicationSettingsBase.this[string].get() C#
ClassLibrary1.Properties.Settings.testval.get() C#
ClassLibrary1.Class1.Add(0x00000005, 0x00000006) C#
ConfigSettingTest.Form1.button1_Click({Text = Cannot evaluate expression
because the code of the current method is optimized.}, {X = 0x00000025 Y =
0x00000021 Button = Left}) C#
As you can see ApplicationSettingsBase will really create
LocalFileSettingsProvider internally. While LocalFileSettingsProvider uses
ClientSettingsStore to read the settings, see the stack trace below:
"ClassLibrary1.Properties.Settings", isUserScoped = false) C#
System.Configuration.LocalFileSettingsProvider.GetPropertyValues(context,
properties = {System.Configuration.SettingsPropertyCollection}) C#
System.Configuration.SettingsBase.GetPropertiesFromProvider(provider) C#
System.Configuration.SettingsBase.GetPropertyValueByName(propertyName =
"testval") C#
System.Configuration.SettingsBase.this[string].get(propertyName) C#
System.Configuration.ApplicationSettingsBase.GetPropertyValue(propertyName
= "testval") C#
System.Configuration.ApplicationSettingsBase.this[string].get(propertyName)
C#
ClassLibrary1.Properties.Settings.testval.get() C#
ClassLibrary1.Class1.Add(a = 0x00000005, b = 0x00000006) C#
ConfigSettingTest.Form1.button1_Click(sender = {Text = Cannot evaluate
expression because the code of the current method is optimized.}, e = {X =
0x0000002f Y = 0x00000029 Button = Left}) C#
While ClientSettingsStore will always read the *Exe* config file. For
example, ClientSettingsStore.GetUserConfig will always
ClientSettingsStore.ClientSettingsConfigurationHost.OpenExeConfiguration to
open the *Exe* file's config file.
private System.Configuration.Configuration GetUserConfig(bool isRoaming)
{
ConfigurationUserLevel level1 = isRoaming ?
ConfigurationUserLevel.PerUserRoaming :
ConfigurationUserLevel.PerUserRoamingAndLocal;
return
ClientSettingsStore.ClientSettingsConfigurationHost.OpenExeConfiguration(lev
el1);
}
So the conclusion is that the ApplicationSettingsBase will always read the
Exe file configure, instead of DLL config file. Also, the
LocalFileSettingsProvider document below also confirms that it will
alreadys read from application.exe.config:
http://msdn2.microsoft.com/en-US/library/system.configuration.localfilesetti
ngsprovider.aspx
In this scenario, if you really wanted to read from the DLL config file, we
have to write a custom provider, thank Mr Sexton for sharing this idea!
Another solution is copying the DLL config file setting into the
application.exe.config.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.