473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using an Exe's My.Settings from a DLL

From the documentation I could find, it seems that reading “appSettingsâ €ť from
the app.config file is now done through ConfigurationMa nager.AppSettin gs for
..NET 2.0, instead of the obsolete ConfigurationSe tting.AppSettin gs. But
what’s kind of confusing is that “appSetttings ” itself seems to be in
disfavor. Accessing “applicationS ettings” using My.Settings seems to be the
preferred way.

1st question: Is My.Settings preferred to using ConfigurationMa nager?

But using My.Settings presents me with this problem. With “appSettingsâ €ť,
the code would always pull values from MyApp.exe.confi g. It did not matter
if the code were in the Exe or some DLL that it used. But now if I use
My.Settings.MyS etting (or My.Settings.Ite m(“MySettingâ €ť) in a non-typed way),
the code will attempt to pull it from the config of the assembly that it is
in. That is, if the code is in the Exe then it will look in
MyApp.exe.confi g, but if it in the DLL then it will look in MyLib.dll.confi g.

2nd question: Is there a “My.Settingsâ €ť way of accessing the config values of
the Executable from code that is in a referenced assembly?

I tried putting “MySetting” in both the app.config files for the Exe and
DLL. I hoped that the Exe value would override the DLL value, but it did not
work. The accessing code in the DLL only found values in MyLib.dll.confi g.
I guess I could resort to doing the semi-new way of using
ConfigurationMa nager to read “appSettingsâ €ť but I am hoping that there is a
general approach to using the Exe’s My.Settings that I haven’t found.

Feb 20 '06 #1
4 8312
Hi Ron,
1st question: Is My.Settings preferred to using ConfigurationMa nager?
Yes, you are right. The .NET 2.0's My.Settings uses the
ConfigurationMa nager class to manipulate the APP Settings.

2nd question: Is there a a€?My.Settingsa €? way of accessing
the config values of the Executable from code that is in a
referenced assembly? I tried putting a€?MySettinga€? in both the app.config files for
the Exe and DLL. I hoped that the Exe value would override the
DLL value, but it did not work. The accessing code in the DLL
only found values in MyLib.dll.confi g.


This behavior is as expected, the EXE's value will not be overided the
value of the assembly which it refereneced. You need to take another
approach to retrieve the application's setting in its referenced assembly.

Thanks for your understanding!
Best regards,

Gary Chang
Microsoft Community Support
=============== =============== =============== =========
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
=============== =============== =============== =========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
=============== =============== =============== =========
This posting is provided "AS IS" with no warranties, and confers no rights.
=============== =============== =============== =========

Feb 21 '06 #2
Do you know of any sample code for using ConfigurationMa nager to read the
"applicationSet tings" section of the config file?

Since you stated that My.Settings uses ConfigurationMa nager to persist the
settings, I know that it should work. My intention is to open
MyApp.exe.confi g from the referenced assembly. I tried the following but it
failed.

Dim file As String
file = AppDomain.Curre ntDomain.Friend lyName & ".config"
Dim exeConfig As Configuration
exeConfig = ConfigurationMa nager.OpenExeCo nfiguration(fil e)
Dim section as ConfigurationSe ction
mySection = exeConfig.GetSe ction("applicat ionSettings")

I know that exeConfig received the correct Configuration since I debugged
and could see exeConfig.Secti ons("appSetting s") values. However,
exeConfig.GetSe ction("applicat ionSettings") returned nothing. What am I
doing wrong?
""Gary Chang[MSFT]"" wrote:
Yes, you are right. The .NET 2.0's My.Settings uses the
ConfigurationMa nager class to manipulate the APP Settings.

This behavior is as expected, the EXE's value will not be overided the
value of the assembly which it refereneced. You need to take another
approach to retrieve the application's setting in its referenced assembly.


Feb 21 '06 #3
I've found that the following code works well enough. If anyone has tips for
improvement, please post them. Thanks.

Dim exeConfig As Configuration
exeConfig = ConfigurationMa nager.OpenExeCo nfiguration _
(ConfigurationU serLevel.None)
Dim sectGroup As ApplicationSett ingsGroup
sectGroup = exeConfig.GetSe ctionGroup("app licationSetting s")
Dim sect As ClientSettingsS ection
sect = sectGroup.Secti ons("MyApp.My.M ySettings")
Dim elm As SettingElement
elm = sect.Settings.G et("MySetting" )
Dim strXml as String = elm.Value.Value Xml.InnerXml

Feb 21 '06 #4
Hi Ron,

Your code is OK, if you have any more concerns on this issue, please feel
free to post here.

Thanks!
Best regards,

Gary Chang
Microsoft Community Support
=============== =============== =============== =========
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
=============== =============== =============== =========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
=============== =============== =============== =========
This posting is provided "AS IS" with no warranties, and confers no rights.
=============== =============== =============== =========

Feb 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16018
by: Dennis Gaida | last post by:
Hi there, I want to upload some exported reports to a FTP Server, for this I use a command line FTP utility. My Database sits in C:\Documents and Settings\Dennis\My Documents\Database The FTP utility sits in C:\Documents and Settings\Dennis\My Documents\Database\oexport The files to be uploaded in C:\Documents and Settings\Dennis\My Documents\Database\oexport\files
9
10904
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
6
3177
by: inpreet | last post by:
I am using App.config to read strings. But when ever I try to read strings in my C# application it always returns null. My App.config ************************************************************ <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSetings> <add key="default_dir" value="c:\\default\file.txt"/> </appSetings> </configuration>
0
1286
by: Luther Hert | last post by:
I solved my problem, but I am not sure whether or not I understand how I arrived at the solution. I leraned about and checked: IIS> creating virtual directories> configuring web extensions > AspNet installation> and installing the lcoalhost web site. When I used Aspnet_regiis.exe to repair IIS Mappings for Asp.Net, my c:\drive directory was altered.
16
9786
by: Asaf | last post by:
I am trying to create and use a COM object with C#.NET 2005. The assembly is set to "Register for COM interop" but when I am trying to call it from VB on Word 2003 I am getting this error: Run-time error '-2147024894 (80070002)': File or assembly name COMTest3, or one of its dependencies, was not found. The code for the COM:
1
5141
by: Matt F | last post by:
Two of the projects in my solution that both need to use a common user.config file. This is a data application - the executable that is created with the first project is the primary executable that users will be working with 99% of the time, the other is a seperate "maintenance" executable. The connection string is stored via My.Settings (encrypted of course). The problem is that obviously with 2 different .exe there are 2 seperate...
0
1493
by: =?Utf-8?B?QWxleA==?= | last post by:
Hi to everyone At the moment, I am converting a .Net 1.1 application to 2.0. As the My.settings did not exist in the 1.1 framework, the "101 VB.NET Sample" "How to configuration settings" was used. At the moment, the App.exe.conf is stored under "Program Files\MyApp". As read/write access is needed to the Application configuration file, I have to change the current approach to get the application running under Windows Vista.
5
4646
Chrisjc
by: Chrisjc | last post by:
Good afternoon, I am seeking some php configuration help. Here is the run down I am running Windows server 2003 and IIS V6.0 I have never had issues before until now. I have Symantec Antivirus 11.0 Manager, it controls all the Symantec clients in the company. Now it uses a web interface for all of its commands and settings which is called (SEPM) This reporting unit uses php, Symantec by default is loading its php.ini from “C:\Program...
11
4467
by: minishilpi | last post by:
I have a question - I have this code below to send an email and I have referenced the Microsoft CDO Library 2000. It doesn't throw any exception in the console window. It goes throughout the code successfully, but I do not receive any email. When I execute this code to send email, it gives the following error - 'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll',...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.