471,594 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Properties.Settings

When using the properties designer to store application wide properties how
do you get this to work across a project group containing an EXE and a
collection of DLLs. I'm using C#.Net 2005. I noticed that the designer
creates and app.config that gets copied to the output directory as a
[programname].exe.config or [dllname].dll.config. In this setup any
Application Scope property that is in the [programname].exe.config file can
be read in from the file and used. My problem is with Application Scope
properties that are in the dlls. Even when I copy the [dllname].dll.config
file to the output directory of the EXE file I can never read in any
application scope parameters from within the dlls. I also tried putting
there settings in the [progname].exe.config file, this also didn't work. Am
I making any sense to anyone? Anyone have any suggestions?

Dave
Jan 23 '07 #1
13 6853
Hi Dave,

Dlls do not use configuration files. If you plan to use Application
Settings from a dll then you must add the settings to the application
configuration file of the EXE that is referencing it. Unfortunately, there
is no way to enforce that users of your dll provide the settings that it
expects in the app's config file or a user settings file, so you have to
handle that contingency by checking for the existence of the properties'
values and either use a hard-coded default or throw an exception if they
aren't present.

An alternative in the 2.0 framework is to create a custom ASP.NET provider
that encapsulates the settings that your dll needs (the provider foundation
works perfectly well in WinForms applications too):

Provider Toolkit
http://msdn2.microsoft.com/en-us/asp.net/aa336558.aspx

For a class library, I prefer to create a custom provider over some
proprietary settings file or Application Settings in most cases.

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:OV*************@TK2MSFTNGP04.phx.gbl...
When using the properties designer to store application wide properties
how
do you get this to work across a project group containing an EXE and a
collection of DLLs. I'm using C#.Net 2005. I noticed that the designer
creates and app.config that gets copied to the output directory as a
[programname].exe.config or [dllname].dll.config. In this setup any
Application Scope property that is in the [programname].exe.config file
can
be read in from the file and used. My problem is with Application Scope
properties that are in the dlls. Even when I copy the
[dllname].dll.config
file to the output directory of the EXE file I can never read in any
application scope parameters from within the dlls. I also tried putting
there settings in the [progname].exe.config file, this also didn't work.
Am
I making any sense to anyone? Anyone have any suggestions?

Dave


Jan 23 '07 #2
Hi Dave,

What type of project you are using to generate the DLL and
"[dllname].dll.config" file? I assume it is Class Library type. By default,
Class Library project type does not contain a Properties.Settings, so you
have to explicitly create one in the project property dialog. I assume you
have done it.

Sorry, I am not sure if I understand you completely. What does the
"Application Scope properties that are in the dlls" mean? Do you mean the
config values you created in the "[dllname].dll.config" file? I can read
them without any problem in the Class Library project. Below is my test
steps:

1. I create a test Winform project and add a Class Library project
2. I open the class library project property dialog and choose "Settings"
tab to explicitly create the "[dllname].dll.config" file for Class Library
project. Then I added a "Application" type int value with name "testval"
and default value "7".
3. I write a very simple static method in the Class Library project which
add 2 input parameters and the default setting value.

namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b +
ClassLibrary1.Properties.Settings.Default.testval;
}
}
}

4. In Winform application project I add the reference to "ClassLibrary1"
project and write the following code to use it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ClassLibrary1.Class1.Add(5, 6).ToString());
}

When I run and click the button, I can get the sum value of "18"(5+6+7)
without any problem. If I have misunderstood you, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '07 #3
Hi Jeffery,

Application Settings may be persisted in a configuration file for a class
library as you've described, however, it's probably worth noting that no
other configuration elements will be loaded by the framework from the class
library's config file. All other configuration settings must be in the
configuration file of the EXE, so two .config files would be required for
the application to run as expected. For this reason, among others, I prefer
to use a provider that can be registered in one place (the EXE's config)
when providing configurable settings for a class library.

With the 2.0 Provider framework you would use an abstract class, which will
provide some level of compile-time checking to ensure that the properties
and methods that provide settings for the class library are at least
implemented by the application. From here, the author of the application
can choose whether to persist the *provided* properties using Application
Settings for the EXE or just use provider settings, which would make more
sense in this case, IMO. That's one config file for normal config settings,
provider settings and even Application Settings with application-scope.

A custom provider provides a contract between the application and the class
library and therefore is more flexible, and only requires a single config
file. Although, using Application Settings is certainly much simpler and
will save time :)

--
Dave Sexton
http://davesexton.com/blog

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:2i**************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

What type of project you are using to generate the DLL and
"[dllname].dll.config" file? I assume it is Class Library type. By
default,
Class Library project type does not contain a Properties.Settings, so you
have to explicitly create one in the project property dialog. I assume you
have done it.

Sorry, I am not sure if I understand you completely. What does the
"Application Scope properties that are in the dlls" mean? Do you mean the
config values you created in the "[dllname].dll.config" file? I can read
them without any problem in the Class Library project. Below is my test
steps:

1. I create a test Winform project and add a Class Library project
2. I open the class library project property dialog and choose "Settings"
tab to explicitly create the "[dllname].dll.config" file for Class Library
project. Then I added a "Application" type int value with name "testval"
and default value "7".
3. I write a very simple static method in the Class Library project which
add 2 input parameters and the default setting value.

namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b +
ClassLibrary1.Properties.Settings.Default.testval;
}
}
}

4. In Winform application project I add the reference to "ClassLibrary1"
project and write the following code to use it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ClassLibrary1.Class1.Add(5, 6).ToString());
}

When I run and click the button, I can get the sum value of "18"(5+6+7)
without any problem. If I have misunderstood you, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 23 '07 #4
Jeffrey,

You can retrieve a value using
"ClassLibrary1.Properties.Settings.Default.testval " like you showed in your
example, but if you go to the config file and change it you will realize its
just giving you the default value that you setup in your property designer.
Not the value that you may have manually setup in your filename.dll.config
file.

Dave
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:2i**************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

What type of project you are using to generate the DLL and
"[dllname].dll.config" file? I assume it is Class Library type. By
default,
Class Library project type does not contain a Properties.Settings, so you
have to explicitly create one in the project property dialog. I assume you
have done it.

Sorry, I am not sure if I understand you completely. What does the
"Application Scope properties that are in the dlls" mean? Do you mean the
config values you created in the "[dllname].dll.config" file? I can read
them without any problem in the Class Library project. Below is my test
steps:

1. I create a test Winform project and add a Class Library project
2. I open the class library project property dialog and choose "Settings"
tab to explicitly create the "[dllname].dll.config" file for Class Library
project. Then I added a "Application" type int value with name "testval"
and default value "7".
3. I write a very simple static method in the Class Library project which
add 2 input parameters and the default setting value.

namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b +
ClassLibrary1.Properties.Settings.Default.testval;
}
}
}

4. In Winform application project I add the reference to "ClassLibrary1"
project and write the following code to use it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ClassLibrary1.Class1.Add(5, 6).ToString());
}

When I run and click the button, I can get the sum value of "18"(5+6+7)
without any problem. If I have misunderstood you, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
>

Jan 23 '07 #5
Thanks for the feedback. I was hoping to not have to do anything as drastic
as creating a provider for a handful of application and user settings.
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uV**************@TK2MSFTNGP04.phx.gbl...
Hi Dave,

Dlls do not use configuration files. If you plan to use Application
Settings from a dll then you must add the settings to the application
configuration file of the EXE that is referencing it. Unfortunately,
there
is no way to enforce that users of your dll provide the settings that it
expects in the app's config file or a user settings file, so you have to
handle that contingency by checking for the existence of the properties'
values and either use a hard-coded default or throw an exception if they
aren't present.

An alternative in the 2.0 framework is to create a custom ASP.NET provider
that encapsulates the settings that your dll needs (the provider
foundation
works perfectly well in WinForms applications too):

Provider Toolkit
http://msdn2.microsoft.com/en-us/asp.net/aa336558.aspx

For a class library, I prefer to create a custom provider over some
proprietary settings file or Application Settings in most cases.

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:OV*************@TK2MSFTNGP04.phx.gbl...
When using the properties designer to store application wide properties
how
do you get this to work across a project group containing an EXE and a
collection of DLLs. I'm using C#.Net 2005. I noticed that the designer
creates and app.config that gets copied to the output directory as a
[programname].exe.config or [dllname].dll.config. In this setup any
Application Scope property that is in the [programname].exe.config file
can
be read in from the file and used. My problem is with Application Scope
properties that are in the dlls. Even when I copy the
[dllname].dll.config
file to the output directory of the EXE file I can never read in any
application scope parameters from within the dlls. I also tried putting
there settings in the [progname].exe.config file, this also didn't work.
Am
I making any sense to anyone? Anyone have any suggestions?

Dave


Jan 23 '07 #6
Hi Dave,

Yea, I understand, but it's not really all that difficult. Also, at the
same location, you can download this:

Code Template For Building a Provider-Based Feature
http://download.microsoft.com/downlo...sedfeature.msi

HTH

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:e$*************@TK2MSFTNGP06.phx.gbl...
Thanks for the feedback. I was hoping to not have to do anything as
drastic
as creating a provider for a handful of application and user settings.
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uV**************@TK2MSFTNGP04.phx.gbl...
>Hi Dave,

Dlls do not use configuration files. If you plan to use Application
Settings from a dll then you must add the settings to the application
configuration file of the EXE that is referencing it. Unfortunately,
there
>is no way to enforce that users of your dll provide the settings that it
expects in the app's config file or a user settings file, so you have to
handle that contingency by checking for the existence of the properties'
values and either use a hard-coded default or throw an exception if they
aren't present.

An alternative in the 2.0 framework is to create a custom ASP.NET
provider
that encapsulates the settings that your dll needs (the provider
foundation
>works perfectly well in WinForms applications too):

Provider Toolkit
http://msdn2.microsoft.com/en-us/asp.net/aa336558.aspx

For a class library, I prefer to create a custom provider over some
proprietary settings file or Application Settings in most cases.

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:OV*************@TK2MSFTNGP04.phx.gbl...
When using the properties designer to store application wide properties
how
do you get this to work across a project group containing an EXE and a
collection of DLLs. I'm using C#.Net 2005. I noticed that the
designer
creates and app.config that gets copied to the output directory as a
[programname].exe.config or [dllname].dll.config. In this setup any
Application Scope property that is in the [programname].exe.config file
can
be read in from the file and used. My problem is with Application
Scope
properties that are in the dlls. Even when I copy the
[dllname].dll.config
file to the output directory of the EXE file I can never read in any
application scope parameters from within the dlls. I also tried
putting
there settings in the [progname].exe.config file, this also didn't
work.
Am
I making any sense to anyone? Anyone have any suggestions?

Dave




Jan 23 '07 #7
Hi Dave,

Interesting - I didn't realize it was only using the DefaultValue attribute,
but that makes sense. The default ApplicationSettingsBase provider is the
LocalFileSettingsProvider, which uses the static configuration methods to
load the application's configuration file for application-scoped settings, I
believe. If the settings is present in the configuration file then the
ApplicationSettingsBase class will just revert back to using the value in
the DefaultSettingValueAttribute.

You may be able to implement a custom SettingsProvider (yep, provider
framework again). I haven't tried it myself but you may be able to extend
the LocalFileSettingsProvider class to load data from your dll's
configuration file for application-scoped settings. However, if you feel
that that's worth the effort, then a custom provider is probably a better
choice.

Application Settings Architecture
http://msdn2.microsoft.com/en-us/library/8eyb2ct1.aspx

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Jeffrey,

You can retrieve a value using
"ClassLibrary1.Properties.Settings.Default.testval " like you showed in
your
example, but if you go to the config file and change it you will realize
its
just giving you the default value that you setup in your property
designer.
Not the value that you may have manually setup in your filename.dll.config
file.

Dave
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:2i**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Dave,

What type of project you are using to generate the DLL and
"[dllname].dll.config" file? I assume it is Class Library type. By
default,
>Class Library project type does not contain a Properties.Settings, so you
have to explicitly create one in the project property dialog. I assume
you
have done it.

Sorry, I am not sure if I understand you completely. What does the
"Application Scope properties that are in the dlls" mean? Do you mean the
config values you created in the "[dllname].dll.config" file? I can read
them without any problem in the Class Library project. Below is my test
steps:

1. I create a test Winform project and add a Class Library project
2. I open the class library project property dialog and choose "Settings"
tab to explicitly create the "[dllname].dll.config" file for Class
Library
project. Then I added a "Application" type int value with name "testval"
and default value "7".
3. I write a very simple static method in the Class Library project which
add 2 input parameters and the default setting value.

namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b +
ClassLibrary1.Properties.Settings.Default.testval ;
}
}
}

4. In Winform application project I add the reference to "ClassLibrary1"
project and write the following code to use it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ClassLibrary1.Class1.Add(5, 6).ToString());
}

When I run and click the button, I can get the sum value of "18"(5+6+7)
without any problem. If I have misunderstood you, please feel free to
tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
================================================= =
This posting is provided "AS IS" with no warranties, and confers no
rights.
>>


Jan 23 '07 #8
Thanks for all your input, I appreciate your suggestions.
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:OF**************@TK2MSFTNGP06.phx.gbl...
Hi Dave,

Interesting - I didn't realize it was only using the DefaultValue
attribute,
but that makes sense. The default ApplicationSettingsBase provider is the
LocalFileSettingsProvider, which uses the static configuration methods to
load the application's configuration file for application-scoped settings,
I
believe. If the settings is present in the configuration file then the
ApplicationSettingsBase class will just revert back to using the value in
the DefaultSettingValueAttribute.

You may be able to implement a custom SettingsProvider (yep, provider
framework again). I haven't tried it myself but you may be able to extend
the LocalFileSettingsProvider class to load data from your dll's
configuration file for application-scoped settings. However, if you feel
that that's worth the effort, then a custom provider is probably a better
choice.

Application Settings Architecture
http://msdn2.microsoft.com/en-us/library/8eyb2ct1.aspx

--
Dave Sexton
http://davesexton.com/blog

"Dave" <Ki************@community.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Jeffrey,

You can retrieve a value using
"ClassLibrary1.Properties.Settings.Default.testval " like you showed in
your
example, but if you go to the config file and change it you will realize
its
just giving you the default value that you setup in your property
designer.
Not the value that you may have manually setup in your
filename.dll.config
file.

Dave
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:2i**************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

What type of project you are using to generate the DLL and
"[dllname].dll.config" file? I assume it is Class Library type. By
default,
Class Library project type does not contain a Properties.Settings, so
you
have to explicitly create one in the project property dialog. I assume
you
have done it.

Sorry, I am not sure if I understand you completely. What does the
"Application Scope properties that are in the dlls" mean? Do you mean
the
config values you created in the "[dllname].dll.config" file? I can
read
them without any problem in the Class Library project. Below is my test
steps:

1. I create a test Winform project and add a Class Library project
2. I open the class library project property dialog and choose
"Settings"
tab to explicitly create the "[dllname].dll.config" file for Class
Library
project. Then I added a "Application" type int value with name
"testval"
and default value "7".
3. I write a very simple static method in the Class Library project
which
add 2 input parameters and the default setting value.

namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b +
ClassLibrary1.Properties.Settings.Default.testval;
}
}
}

4. In Winform application project I add the reference to
"ClassLibrary1"
project and write the following code to use it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ClassLibrary1.Class1.Add(5, 6).ToString());
}

When I run and click the button, I can get the sum value of "18"(5+6+7)
without any problem. If I have misunderstood you, please feel free to
tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
>


Jan 23 '07 #9
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.LocalFileSettingsProvider.Ini tialize(null, null) C#
System.Configuration.ApplicationSettingsBase.Initi alizer.get() C#

System.Configuration.ApplicationSettingsBase.Creat eSetting({System.Reflectio
n.RuntimePropertyInfo}) C#
System.Configuration.ApplicationSettingsBase.Ensur eInitialized() C#
System.Configuration.ApplicationSettingsBase.Prope rties.get() C#
System.Configuration.SettingsBase.GetPropertyValue ByName("testval") C#
System.Configuration.SettingsBase.this[string].get() C#
System.Configuration.ApplicationSettingsBase.GetPr opertyValue("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:
> System.Configuration.ClientSettingsStore.ReadSetti ngs(sectionName =
"ClassLibrary1.Properties.Settings", isUserScoped = false) C#
System.Configuration.LocalFileSettingsProvider.Get PropertyValues(context,
properties = {System.Configuration.SettingsPropertyCollection}) C#
System.Configuration.SettingsBase.GetPropertiesFro mProvider(provider) C#
System.Configuration.SettingsBase.GetPropertyValue ByName(propertyName =
"testval") C#
System.Configuration.SettingsBase.this[string].get(propertyName) C#

System.Configuration.ApplicationSettingsBase.GetPr opertyValue(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.ClientSettingsConfigurationHos t.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.ClientSettingsConfigurationHos t.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/lib...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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Jan 24 '07 #10
Sorry, I post the reply too quick.

To allow the DLL code "ClassLibrary1.Properties.Settings.Default.testval "
to read the App.Exe.Config setting, you should add the
"ClassLibrary1.Properties.Settings" section in the "[dllname].dll.config"
to the application.exe.config under <applicationSettingssection. Also,
you should add <section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/under <configSections>. Below is the full application.exe.config I used
after copying the "[dllname].dll.config" setting into
application.exe.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigSettingTest.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>

</configSections>
<applicationSettings>
<ConfigSettingTest.Properties.Settings>
<setting name="intvalue" serializeAs="String">
<value>5</value>
</setting>
</ConfigSettingTest.Properties.Settings>
<ClassLibrary1.Properties.Settings>
<setting name="testval" serializeAs="String">
<value>1000</value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>
</configuration>

Now, my testing application can read the modified "1000" value from
"ClassLibrary1.Properties.Settings.Default.testval " without any problem.

If you still need any help or have any concern, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 24 '07 #11
Hi Jeffery,

In a related post in this newsgroup on 1/23/07, Walter Wang [MSFT] suggested
another approach as well that doesn't require importing config settings from
the dll into the exe, however, I'd still caution anyone that is willing to
use multiple configuration files for a single application. But, it's
another possibility.

HTH

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:jm**************@TK2MSFTNGHUB02.phx.gbl...
Sorry, I post the reply too quick.

To allow the DLL code "ClassLibrary1.Properties.Settings.Default.testval "
to read the App.Exe.Config setting, you should add the
"ClassLibrary1.Properties.Settings" section in the "[dllname].dll.config"
to the application.exe.config under <applicationSettingssection. Also,
you should add <section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/under <configSections>. Below is the full application.exe.config I used
after copying the "[dllname].dll.config" setting into
application.exe.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigSettingTest.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
</sectionGroup>

</configSections>
<applicationSettings>
<ConfigSettingTest.Properties.Settings>
<setting name="intvalue" serializeAs="String">
<value>5</value>
</setting>
</ConfigSettingTest.Properties.Settings>
<ClassLibrary1.Properties.Settings>
<setting name="testval" serializeAs="String">
<value>1000</value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>
</configuration>

Now, my testing application can read the modified "1000" value from
"ClassLibrary1.Properties.Settings.Default.testval " without any problem.

If you still need any help or have any concern, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 24 '07 #12
Hi,

Sorry, I should have given the thread's name:

Gettings settings values in an assembly library from an ASP.NET or Winform

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:jm**************@TK2MSFTNGHUB02.phx.gbl...
Sorry, I post the reply too quick.

To allow the DLL code "ClassLibrary1.Properties.Settings.Default.testval "
to read the App.Exe.Config setting, you should add the
"ClassLibrary1.Properties.Settings" section in the "[dllname].dll.config"
to the application.exe.config under <applicationSettingssection. Also,
you should add <section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/under <configSections>. Below is the full application.exe.config I used
after copying the "[dllname].dll.config" setting into
application.exe.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigSettingTest.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
</sectionGroup>

</configSections>
<applicationSettings>
<ConfigSettingTest.Properties.Settings>
<setting name="intvalue" serializeAs="String">
<value>5</value>
</setting>
</ConfigSettingTest.Properties.Settings>
<ClassLibrary1.Properties.Settings>
<setting name="testval" serializeAs="String">
<value>1000</value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>
</configuration>

Now, my testing application can read the modified "1000" value from
"ClassLibrary1.Properties.Settings.Default.testval " without any problem.

If you still need any help or have any concern, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 24 '07 #13
Hi Mr Sexton,

Thank you for sharing this.

Yes, I have talked with my colleague Walter Wang [MSFT] with this
issue(yes, we are in the same team :-) ). We believe that there is no
perfect workaround to this scenario, using the "configSource" element still
needs some modification to the app.exe.config file. Since the first reply
of OP failed to merge dll.config with the app.exe.config, I posted the
steps and format to combine them.

Anyway, let's wait for Dave(OP)'s further feedback. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 25 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by randy1200 | last post: by
4 posts views Thread by Shak | last post: by
3 posts views Thread by Steve Long | last post: by
reply views Thread by =?Utf-8?B?UmljayBHbG9z?= | last post: by
1 post views Thread by =?Utf-8?B?VGVlcmF2ZWU=?= | last post: by
2 posts views Thread by Jan Eliasen | last post: by
3 posts views Thread by Morten Snedker | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.