473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to get app.config info from code in a referenced class

I have a winforms project Vs2005 with one project - Project1 which is the
startup project and clsProject2 which is a class that is being used by
Project1 (an exception handler). In clsProject2 I have a procedure that must
take information from the app.config file of Project1. In the clsproject2 I
need to write code that gets the value of a setting in the app.config file
of Project1. I find that the code I had that seemed to work ijn Vs2003 now
no longer picks up the data in the Project1 app.config. Exactly how would I
be able to use code in clsProject2 to get configuration info from Project1
app.config.
I want to try to get the info via clsProject2 so that I can reuse the same
class without writing too much code in the calling projects to come later.

Any help would be really appreciated.

Thanks for any help.
Bob
Nov 15 '06 #1
8 1774
"Robert Dufour" <bd*****@sgiims.comwrote in
news:e9**************@TK2MSFTNGP06.phx.gbl:
Exactly how would I
be able to use code in clsProject2 to get configuration info from
Project1 app.config.
I want to try to get the info via clsProject2 so that I can reuse the
same class without writing too much code in the calling projects to
come later.
clsProject2 is a library right?

In that case it'll run in the appDomain of it's parent process - thus it'll
use the parent's app.config.

So just go AppSetting("MyKey") - it'll pick it up from Project1's
app.config.
Nov 15 '06 #2
Thanks
Bob

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Robert Dufour" <bd*****@sgiims.comwrote in
news:e9**************@TK2MSFTNGP06.phx.gbl:
>Exactly how would I
be able to use code in clsProject2 to get configuration info from
Project1 app.config.
I want to try to get the info via clsProject2 so that I can reuse the
same class without writing too much code in the calling projects to
come later.

clsProject2 is a library right?

In that case it'll run in the appDomain of it's parent process - thus
it'll
use the parent's app.config.

So just go AppSetting("MyKey") - it'll pick it up from Project1's
app.config.

Nov 15 '06 #3
Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot be
used as an expression".

Bob

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Robert Dufour" <bd*****@sgiims.comwrote in
news:e9**************@TK2MSFTNGP06.phx.gbl:
>Exactly how would I
be able to use code in clsProject2 to get configuration info from
Project1 app.config.
I want to try to get the info via clsProject2 so that I can reuse the
same class without writing too much code in the calling projects to
come later.

clsProject2 is a library right?

In that case it'll run in the appDomain of it's parent process - thus
it'll
use the parent's app.config.

So just go AppSetting("MyKey") - it'll pick it up from Project1's
app.config.

Nov 15 '06 #4
"Robert Dufour" <bd*****@sgiims.comwrote in news:#Y9IKePCHHA.3836
@TK2MSFTNGP02.phx.gbl:
Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot be
used as an expression".
You need to import the ConfigurationSettings class (System.Configuration)
or the new Configuration Manager class (you need to reference the
System.Configuration DLL).
Nov 15 '06 #5
Thanks for your help. Still having a problem though. I referenced the new
configuration manager class. The wavy warning is gone and my code executes
without any exceptions, BUT it does not pick up any of the values in the
config file.
When I single step over the following line in the debugger strTemp remains
empty but there is a value for it in the config file.
Dim strTemp As String = AppSettings.GetString(strKey) - strkey is a
variable passed to this procedure, the spelling of the variable value is
correct.

Isn't high tech fun?

Thanks for your help

Bob

<Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Robert Dufour" <bd*****@sgiims.comwrote in news:#Y9IKePCHHA.3836
@TK2MSFTNGP02.phx.gbl:
>Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot be
used as an expression".

You need to import the ConfigurationSettings class (System.Configuration)
or the new Configuration Manager class (you need to reference the
System.Configuration DLL).

Nov 15 '06 #6
How 'bout the case of the variable. XML is case sensitive.

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thanks for your help. Still having a problem though. I referenced the new
configuration manager class. The wavy warning is gone and my code executes
without any exceptions, BUT it does not pick up any of the values in the
config file.
When I single step over the following line in the debugger strTemp remains
empty but there is a value for it in the config file.
Dim strTemp As String = AppSettings.GetString(strKey) - strkey is a
variable passed to this procedure, the spelling of the variable value is
correct.

Isn't high tech fun?

Thanks for your help

Bob

<Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
>"Robert Dufour" <bd*****@sgiims.comwrote in news:#Y9IKePCHHA.3836
@TK2MSFTNGP02.phx.gbl:
>>Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot be
used as an expression".

You need to import the ConfigurationSettings class (System.Configuration)
or the new Configuration Manager class (you need to reference the
System.Configuration DLL).


Nov 15 '06 #7
Yes I know, I double checked, case of the variable is OK.
Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:uK**************@TK2MSFTNGP06.phx.gbl...
How 'bout the case of the variable. XML is case sensitive.

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Thanks for your help. Still having a problem though. I referenced the new
configuration manager class. The wavy warning is gone and my code
executes without any exceptions, BUT it does not pick up any of the
values in the config file.
When I single step over the following line in the debugger strTemp
remains empty but there is a value for it in the config file.
Dim strTemp As String = AppSettings.GetString(strKey) - strkey is a
variable passed to this procedure, the spelling of the variable value is
correct.

Isn't high tech fun?

Thanks for your help

Bob

<Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0 .1...
>>"Robert Dufour" <bd*****@sgiims.comwrote in news:#Y9IKePCHHA.3836
@TK2MSFTNGP02.phx.gbl:

Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot
be
used as an expression".

You need to import the ConfigurationSettings class
(System.Configuration)
or the new Configuration Manager class (you need to reference the
System.Configuration DLL).



Nov 16 '06 #8
Simple sample demonstrating the problem consists of a solution containing a
class project and a windows form project. I put the same in a new thread
also, hope thats OK.

Here's the class code snippet
Imports System.Configuration.ConfigurationManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

_strTestSetting = AppSettings.Get("TestSetting") -should get the value of
TestSetting in app config file

End Sub
End Class

This is the snippet in the project calling the class -Project TestIt - To
test you should have a setting named TestSetting application scope, value
Testvalue

Imports System.Configuration

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim mycls As New clsTestconfig.Class1

mycls.SetTestsetting()

Label1.Text = mycls._strTestSetting

End Sub

End Class

There's a setting TestSetting in the settings file of the project Testit

Put a breakpoint on line

_strTestSetting = AppSettings.Get("TestSetting")

Click the button, you will see as you step over the breakpoint that the
value of _strTestSetting stays at nothing. ie, its not picking up the value
of TestSetting in app.config.

How can I get this pickup of the value to work? By the way I tested in the
IDE and the exe itself. Both failed same way.

Thanks for any help

Bob

"Steve Long" <St**********@NoSpam.comwrote in message
news:uK**************@TK2MSFTNGP06.phx.gbl...
How 'bout the case of the variable. XML is case sensitive.

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Thanks for your help. Still having a problem though. I referenced the new
configuration manager class. The wavy warning is gone and my code
executes without any exceptions, BUT it does not pick up any of the
values in the config file.
When I single step over the following line in the debugger strTemp
remains empty but there is a value for it in the config file.
Dim strTemp As String = AppSettings.GetString(strKey) - strkey is a
variable passed to this procedure, the spelling of the variable value is
correct.

Isn't high tech fun?

Thanks for your help

Bob

<Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0 .1...
>>"Robert Dufour" <bd*****@sgiims.comwrote in news:#Y9IKePCHHA.3836
@TK2MSFTNGP02.phx.gbl:

Hi, when I try that
Dim strTemp As String = AppSettings("mysetting")

I get the wavy blue underlines and "appsettings is a type and cannot
be
used as an expression".

You need to import the ConfigurationSettings class
(System.Configuration)
or the new Configuration Manager class (you need to reference the
System.Configuration DLL).



Nov 16 '06 #9

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

Similar topics

1
by: José Joye | last post by:
Hello, I have an assembly that is used by a VB6 application. This application can be a normal exe or an ActiveX (called through CCW). My assembly needs to get extra info from a config file. In...
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
4
by: Ed_P. | last post by:
Hello, I have the following scenario: I have a solution with 4 projects Project1 = MainWindow (Windows EXE) Project2 = PresentationLayer (DLL) Project3 = BusinessLayer (DLL) Project4 =...
5
by: Daniel | last post by:
Hi, is the a way to prevent aspnet process to restart after web.config is modified? like, waiting for all sessions to close, or not restart at all ? Thank you, Daniel
3
by: Christopher Kimbell | last post by:
I have a class library that contains a number of TableAdapters and I'm using this from a web application. Is there a way of getting the TableAdapters to use the connectionstrings defined in...
3
by: andrew.fabbro | last post by:
I'm working on an app that will be deployed on several different servers. In each case, I'll want to change some config info (database name, paths, etc.) In perl, I would have done something...
1
by: David Williams | last post by:
Has the Schema of the Web.Config changed in Web App Projects? After converting my 2005 Web Site project to a 2005 WAP, and switching to IIS Web Server, I am getting a number of errors at run time...
8
by: aabdis | last post by:
Hello All.... I have a question... i have two Windows apps (one UI, and one service) which use a common DLL that hands out database results and such to the two apps. The DLL always connects to...
6
by: TS | last post by:
I cannot get this to work. I added an app.config to a project i reference from my web application project (vs 05) but can see no way to access the settings within it. the other thing is that I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.