|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to get app.config info from code in a referenced classI 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 "Robert Dufour" <bduf***@sgiims.com> wrote in clsProject2 is a library right?news:e9cEfIPCHHA.5012@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. > 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. Thanks
Bob Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns987C9B46147C3usenethoneypotrogers@127.0.0.1... > "Robert Dufour" <bduf***@sgiims.com> wrote in > news:e9cEfIPCHHA.5012@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. 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 Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns987C9B46147C3usenethoneypotrogers@127.0.0.1... > "Robert Dufour" <bduf***@sgiims.com> wrote in > news:e9cEfIPCHHA.5012@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. "Robert Dufour" <bduf***@sgiims.com> wrote in news:#Y9IKePCHHA.3836 @TK2MSFTNGP02.phx.gbl:> Hi, when I try that You need to import the ConfigurationSettings class (System.Configuration) > Dim strTemp As String = AppSettings("mysetting") > > I get the wavy blue underlines and "appsettings is a type and cannot be > used as an expression". or the new Configuration Manager class (you need to reference the System.Configuration DLL). 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" <spamhoneypot@rogers.com> wrote in message Show quoteHide quote news:Xns987CA5F26C168usenethoneypotrogers@127.0.0.1... > "Robert Dufour" <bduf***@sgiims.com> wrote 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). How 'bout the case of the variable. XML is case sensitive.
S Show quoteHide quote "Robert Dufour" <bduf***@sgiims.com> wrote in message news:%23Fvdv9PCHHA.3540@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" <spamhoneypot@rogers.com> wrote in message > news:Xns987CA5F26C168usenethoneypotrogers@127.0.0.1... > >> "Robert Dufour" <bduf***@sgiims.com> wrote 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). > > Yes I know, I double checked, case of the variable is OK.
Bob Show quoteHide quote "Steve Long" <Steve_Noneya@NoSpam.com> wrote in message news:uKEpPOQCHHA.4464@TK2MSFTNGP06.phx.gbl... > How 'bout the case of the variable. XML is case sensitive. > > S > > "Robert Dufour" <bduf***@sgiims.com> wrote in message > news:%23Fvdv9PCHHA.3540@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" <spamhoneypot@rogers.com> wrote in message >> news:Xns987CA5F26C168usenethoneypotrogers@127.0.0.1... >> >>> "Robert Dufour" <bduf***@sgiims.com> wrote 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). >> >> > > 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 Show quoteHide quote "Steve Long" <Steve_Noneya@NoSpam.com> wrote in message news:uKEpPOQCHHA.4464@TK2MSFTNGP06.phx.gbl... > How 'bout the case of the variable. XML is case sensitive. > > S > > "Robert Dufour" <bduf***@sgiims.com> wrote in message > news:%23Fvdv9PCHHA.3540@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" <spamhoneypot@rogers.com> wrote in message >> news:Xns987CA5F26C168usenethoneypotrogers@127.0.0.1... >> >>> "Robert Dufour" <bduf***@sgiims.com> wrote 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). >> >> > >
VB.NET and MDAC+JET
There is no conditional And in VB? Upgrade? VB 2005 and Windows vista Reference parent form elemets by child update access mdb Strange but true ... im at a loss help !!! question about inheritance and Imports statement XML over TCP directing output to selected monitor in a multi-monitor desktop |
|||||||||||||||||||||||