Problems accessing configuration file in .NET 2.0

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stacey

    Problems accessing configuration file in .NET 2.0

    I am using Visual Studio 2005, creating a VB.NET program. I am have created
    a settings file and two settings in the file. The section that it created
    in my app.config is below. I can not figure out how to access the two
    settings. I need to be able to get the data out of the settings. And update
    them at a later point as well. I have tried all sorts of things.
    Dim CurReceipt As Integer =
    CInt(Configurat ionManager.AppS ettings("Receip tNumber"))

    Dim CurTrans As Int64 =
    CLng(Configurat ionManager.AppS ettings("Transa ctionNUmber"))

    Each of the above lines just return 0. According to the help file, i
    should be able to use My.Settings.Rec eiptNumber - but that is not
    available. Any ideas? Thanks
    Stacey

    <applicationSet tings>

    <GiftGards.Card s>

    <setting name="ReceiptNu mber" serializeAs="St ring">

    <value>50</value>

    </setting>

    <setting name="Transacti onNumber" serializeAs="St ring">

    <value>1000</value>

    </setting>

    </GiftGards.Cards >

    </applicationSett ings>

    -----------WARNINGS AND ERROR MESSAGES BELOW-------------
    Warning 1 The 'requirePermiss ion' attribute is not declared. D:\Projects
    ..NET\RTCGiftGa rds\RTCGiftGard s\app.config 5 176 RTCGiftGards
    Message 2 Could not find schema information for the element
    'applicationSet tings'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config
    30 6 RTCGiftGards
    Message 3 Could not find schema information for the element
    'RTCGiftGards.R TCCards'. D:\Projects
    ..NET\RTCGiftGa rds\RTCGiftGard s\app.config 31 10 RTCGiftGards
    Message 4 Could not find schema information for the element 'setting'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 14 RTCGiftGards
    Message 5 Could not find schema information for the attribute 'name'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 22 RTCGiftGards
    Message 6 Could not find schema information for the attribute 'serializeAs'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 43 RTCGiftGards
    Message 7 Could not find schema information for the element 'value'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 33 18 RTCGiftGards
    Message 8 Could not find schema information for the element 'setting'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 14 RTCGiftGards
    Message 9 Could not find schema information for the attribute 'name'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 22 RTCGiftGards
    Message 10 Could not find schema information for the attribute
    'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 47
    RTCGiftGards
    Message 11 Could not find schema information for the element 'value'.
    D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 36 18 RTCGiftGards


  • Andrew Kidd

    #2
    Re: Problems accessing configuration file in .NET 2.0

    Hi Stacey ... I've just been working on something similar myself.

    The upshot is that your settings cannot be written to the app.config file,
    since it is read-only at run-time. Instead, you should use the user.config
    file ... have a look at this -
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.




    "Stacey" <StaceyL@commun ity.nospam> wrote in message
    news:uEmJOsp9FH A.2676@TK2MSFTN GP15.phx.gbl...[color=blue]
    >I am using Visual Studio 2005, creating a VB.NET program. I am have created
    >a settings file and two settings in the file. The section that it created
    >in my app.config is below. I can not figure out how to access the two
    >settings. I need to be able to get the data out of the settings. And
    >update them at a later point as well. I have tried all sorts of things.
    > Dim CurReceipt As Integer =
    > CInt(Configurat ionManager.AppS ettings("Receip tNumber"))
    >
    > Dim CurTrans As Int64 =
    > CLng(Configurat ionManager.AppS ettings("Transa ctionNUmber"))
    >
    > Each of the above lines just return 0. According to the help file, i
    > should be able to use My.Settings.Rec eiptNumber - but that is not
    > available. Any ideas? Thanks
    > Stacey
    >
    > <applicationSet tings>
    >
    > <GiftGards.Card s>
    >
    > <setting name="ReceiptNu mber" serializeAs="St ring">
    >
    > <value>50</value>
    >
    > </setting>
    >
    > <setting name="Transacti onNumber" serializeAs="St ring">
    >
    > <value>1000</value>
    >
    > </setting>
    >
    > </GiftGards.Cards >
    >
    > </applicationSett ings>
    >
    > -----------WARNINGS AND ERROR MESSAGES BELOW-------------
    > Warning 1 The 'requirePermiss ion' attribute is not declared. D:\Projects
    > .NET\RTCGiftGar ds\RTCGiftGards \app.config 5 176 RTCGiftGards
    > Message 2 Could not find schema information for the element
    > 'applicationSet tings'. D:\Projects
    > .NET\RTCGiftGar ds\RTCGiftGards \app.config 30 6 RTCGiftGards
    > Message 3 Could not find schema information for the element
    > 'RTCGiftGards.R TCCards'. D:\Projects
    > .NET\RTCGiftGar ds\RTCGiftGards \app.config 31 10 RTCGiftGards
    > Message 4 Could not find schema information for the element 'setting'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 14 RTCGiftGards
    > Message 5 Could not find schema information for the attribute 'name'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 22 RTCGiftGards
    > Message 6 Could not find schema information for the attribute
    > 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 43
    > RTCGiftGards
    > Message 7 Could not find schema information for the element 'value'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 33 18 RTCGiftGards
    > Message 8 Could not find schema information for the element 'setting'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 14 RTCGiftGards
    > Message 9 Could not find schema information for the attribute 'name'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 22 RTCGiftGards
    > Message 10 Could not find schema information for the attribute
    > 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 47
    > RTCGiftGards
    > Message 11 Could not find schema information for the element 'value'.
    > D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 36 18 RTCGiftGards
    >
    >[/color]


    Comment

    • Stacey

      #3
      Re: Problems accessing configuration file in .NET 2.0

      Unless I am missing things, I am doing it that way. I told it to create a
      new settings file. and it does.. but it also writes the entires into the
      app.config. The file it creates is called RTCCards.settin gs and it has my
      two values in it.

      "Andrew Kidd" <andrew@nospam. com> wrote in message
      news:OeKMcFq9FH A.3060@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi Stacey ... I've just been working on something similar myself.
      >
      > The upshot is that your settings cannot be written to the app.config file,
      > since it is read-only at run-time. Instead, you should use the user.config
      > file ... have a look at this -
      > http://msdn.microsoft.com/library/en...asp?frame=true
      >
      >
      >
      > "Stacey" <StaceyL@commun ity.nospam> wrote in message
      > news:uEmJOsp9FH A.2676@TK2MSFTN GP15.phx.gbl...[color=green]
      >>I am using Visual Studio 2005, creating a VB.NET program. I am have
      >>created a settings file and two settings in the file. The section that it
      >>created in my app.config is below. I can not figure out how to access the
      >>two settings. I need to be able to get the data out of the settings. And
      >>update them at a later point as well. I have tried all sorts of things.
      >> Dim CurReceipt As Integer =
      >> CInt(Configurat ionManager.AppS ettings("Receip tNumber"))
      >>
      >> Dim CurTrans As Int64 =
      >> CLng(Configurat ionManager.AppS ettings("Transa ctionNUmber"))
      >>
      >> Each of the above lines just return 0. According to the help file, i
      >> should be able to use My.Settings.Rec eiptNumber - but that is not
      >> available. Any ideas? Thanks
      >> Stacey
      >>
      >> <applicationSet tings>
      >>
      >> <GiftGards.Card s>
      >>
      >> <setting name="ReceiptNu mber" serializeAs="St ring">
      >>
      >> <value>50</value>
      >>
      >> </setting>
      >>
      >> <setting name="Transacti onNumber" serializeAs="St ring">
      >>
      >> <value>1000</value>
      >>
      >> </setting>
      >>
      >> </GiftGards.Cards >
      >>
      >> </applicationSett ings>
      >>
      >> -----------WARNINGS AND ERROR MESSAGES BELOW-------------
      >> Warning 1 The 'requirePermiss ion' attribute is not declared. D:\Projects
      >> .NET\RTCGiftGar ds\RTCGiftGards \app.config 5 176 RTCGiftGards
      >> Message 2 Could not find schema information for the element
      >> 'applicationSet tings'. D:\Projects
      >> .NET\RTCGiftGar ds\RTCGiftGards \app.config 30 6 RTCGiftGards
      >> Message 3 Could not find schema information for the element
      >> 'RTCGiftGards.R TCCards'. D:\Projects
      >> .NET\RTCGiftGar ds\RTCGiftGards \app.config 31 10 RTCGiftGards
      >> Message 4 Could not find schema information for the element 'setting'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 14 RTCGiftGards
      >> Message 5 Could not find schema information for the attribute 'name'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 22 RTCGiftGards
      >> Message 6 Could not find schema information for the attribute
      >> 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32
      >> 43 RTCGiftGards
      >> Message 7 Could not find schema information for the element 'value'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 33 18 RTCGiftGards
      >> Message 8 Could not find schema information for the element 'setting'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 14 RTCGiftGards
      >> Message 9 Could not find schema information for the attribute 'name'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 22 RTCGiftGards
      >> Message 10 Could not find schema information for the attribute
      >> 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35
      >> 47 RTCGiftGards
      >> Message 11 Could not find schema information for the element 'value'.
      >> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 36 18 RTCGiftGards
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • m.posseth

        #4
        Re: Problems accessing configuration file in .NET 2.0

        well to save yourselves a lot of trouble

        use Francesco`s class ,,, VB.Net and C# version availlable


        I use this class in 2003 and 2005

        regards

        Michel Posseth [MCP]


        "Stacey" <StaceyL@commun ity.nospam> schreef in bericht
        news:eKvixWq9FH A.2036@TK2MSFTN GP14.phx.gbl...[color=blue]
        > Unless I am missing things, I am doing it that way. I told it to create a
        > new settings file. and it does.. but it also writes the entires into the
        > app.config. The file it creates is called RTCCards.settin gs and it has my
        > two values in it.
        >
        > "Andrew Kidd" <andrew@nospam. com> wrote in message
        > news:OeKMcFq9FH A.3060@TK2MSFTN GP10.phx.gbl...[color=green]
        >> Hi Stacey ... I've just been working on something similar myself.
        >>
        >> The upshot is that your settings cannot be written to the app.config
        >> file, since it is read-only at run-time. Instead, you should use the
        >> user.config file ... have a look at this -
        >> http://msdn.microsoft.com/library/en...asp?frame=true
        >>
        >>
        >>
        >> "Stacey" <StaceyL@commun ity.nospam> wrote in message
        >> news:uEmJOsp9FH A.2676@TK2MSFTN GP15.phx.gbl...[color=darkred]
        >>>I am using Visual Studio 2005, creating a VB.NET program. I am have
        >>>created a settings file and two settings in the file. The section that
        >>>it created in my app.config is below. I can not figure out how to access
        >>>the two settings. I need to be able to get the data out of the settings.
        >>>And update them at a later point as well. I have tried all sorts of
        >>>things.
        >>> Dim CurReceipt As Integer =
        >>> CInt(Configurat ionManager.AppS ettings("Receip tNumber"))
        >>>
        >>> Dim CurTrans As Int64 =
        >>> CLng(Configurat ionManager.AppS ettings("Transa ctionNUmber"))
        >>>
        >>> Each of the above lines just return 0. According to the help file, i
        >>> should be able to use My.Settings.Rec eiptNumber - but that is not
        >>> available. Any ideas? Thanks
        >>> Stacey
        >>>
        >>> <applicationSet tings>
        >>>
        >>> <GiftGards.Card s>
        >>>
        >>> <setting name="ReceiptNu mber" serializeAs="St ring">
        >>>
        >>> <value>50</value>
        >>>
        >>> </setting>
        >>>
        >>> <setting name="Transacti onNumber" serializeAs="St ring">
        >>>
        >>> <value>1000</value>
        >>>
        >>> </setting>
        >>>
        >>> </GiftGards.Cards >
        >>>
        >>> </applicationSett ings>
        >>>
        >>> -----------WARNINGS AND ERROR MESSAGES BELOW-------------
        >>> Warning 1 The 'requirePermiss ion' attribute is not declared. D:\Projects
        >>> .NET\RTCGiftGar ds\RTCGiftGards \app.config 5 176 RTCGiftGards
        >>> Message 2 Could not find schema information for the element
        >>> 'applicationSet tings'. D:\Projects
        >>> .NET\RTCGiftGar ds\RTCGiftGards \app.config 30 6 RTCGiftGards
        >>> Message 3 Could not find schema information for the element
        >>> 'RTCGiftGards.R TCCards'. D:\Projects
        >>> .NET\RTCGiftGar ds\RTCGiftGards \app.config 31 10 RTCGiftGards
        >>> Message 4 Could not find schema information for the element 'setting'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 14 RTCGiftGards
        >>> Message 5 Could not find schema information for the attribute 'name'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32 22 RTCGiftGards
        >>> Message 6 Could not find schema information for the attribute
        >>> 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 32
        >>> 43 RTCGiftGards
        >>> Message 7 Could not find schema information for the element 'value'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 33 18 RTCGiftGards
        >>> Message 8 Could not find schema information for the element 'setting'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 14 RTCGiftGards
        >>> Message 9 Could not find schema information for the attribute 'name'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35 22 RTCGiftGards
        >>> Message 10 Could not find schema information for the attribute
        >>> 'serializeAs'. D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 35
        >>> 47 RTCGiftGards
        >>> Message 11 Could not find schema information for the element 'value'.
        >>> D:\Projects .NET\RTCGiftGar ds\RTCGiftGards \app.config 36 18 RTCGiftGards
        >>>
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Jeffrey Tan[MSFT]

          #5
          RE: Problems accessing configuration file in .NET 2.0

          Hi StaceyL,

          Thanks for your post.

          Can you show us how you added the settings in app.config? Do you use the
          Settings.settin gs designer?

          Normally, after we adding the setting in the designer, we should can refer
          the item with My.Settings.[item name] in VB.net code file.

          If you failed to do this, can you provide some detailed steps to reproduce
          your problem?

          Below is the official document for manipulating the application settings in
          VS2005:
          "Accessing Application Settings "

          "Managing Application Settings"


          Thanks

          Best regards,
          Jeffrey Tan
          Microsoft Online Partner Support
          Get Secure! - www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          Comment

          • Stacey

            #6
            Re: Problems accessing configuration file in .NET 2.0

            I added the strings using the designer. Ie.. right click on the solution.
            Add --> New --> Settings file. Enter my two settings into the settings file.
            They are not accessible.

            ""Jeffrey Tan[MSFT]"" <v-jetan@online.mi crosoft.com> wrote in message
            news:FDSuS4u9FH A.1236@TK2MSFTN GXA02.phx.gbl.. .[color=blue]
            > Hi StaceyL,
            >
            > Thanks for your post.
            >
            > Can you show us how you added the settings in app.config? Do you use the
            > Settings.settin gs designer?
            >
            > Normally, after we adding the setting in the designer, we should can refer
            > the item with My.Settings.[item name] in VB.net code file.
            >
            > If you failed to do this, can you provide some detailed steps to reproduce
            > your problem?
            >
            > Below is the official document for manipulating the application settings
            > in
            > VS2005:
            > "Accessing Application Settings "
            > http://msdn2.microsoft.com/en-us/library/bc6ws923.aspx
            > "Managing Application Settings"
            > http://msdn2.microsoft.com/en-us/library/c9db58th.aspx
            >
            > Thanks
            >
            > Best regards,
            > Jeffrey Tan
            > Microsoft Online Partner Support
            > Get Secure! - www.microsoft.com/security
            > This posting is provided "as is" with no warranties and confers no rights.
            >[/color]


            Comment

            • Stacey

              #7
              Re: Problems accessing configuration file in .NET 2.0

              Additionally, you can download a small sample project that shows the
              problem.




              ""Jeffrey Tan[MSFT]"" <v-jetan@online.mi crosoft.com> wrote in message
              news:FDSuS4u9FH A.1236@TK2MSFTN GXA02.phx.gbl.. .[color=blue]
              > Hi StaceyL,
              >
              > Thanks for your post.
              >
              > Can you show us how you added the settings in app.config? Do you use the
              > Settings.settin gs designer?
              >
              > Normally, after we adding the setting in the designer, we should can refer
              > the item with My.Settings.[item name] in VB.net code file.
              >
              > If you failed to do this, can you provide some detailed steps to reproduce
              > your problem?
              >
              > Below is the official document for manipulating the application settings
              > in
              > VS2005:
              > "Accessing Application Settings "
              > http://msdn2.microsoft.com/en-us/library/bc6ws923.aspx
              > "Managing Application Settings"
              > http://msdn2.microsoft.com/en-us/library/c9db58th.aspx
              >
              > Thanks
              >
              > Best regards,
              > Jeffrey Tan
              > Microsoft Online Partner Support
              > Get Secure! - www.microsoft.com/security
              > This posting is provided "as is" with no warranties and confers no rights.
              >[/color]


              Comment

              • Jeffrey Tan[MSFT]

                #8
                Re: Problems accessing configuration file in .NET 2.0

                Hi Stacey,

                Thanks for your feedback.

                No, we should not add a new Settings.settin gs file. We should use the
                default Settings.settin gs file to store the application/user config data.
                Then VB.net20005 designer will associate them in My.Settings class.

                To use the default Settings.settin gs file, we can right click Project node
                in the solution explorer, then choose the "Properties " to open the "Project
                Properties" tab. Then we can click "Settings" tab in the "Project
                Properties" tab. At last, we can set the config data in the designer.

                After this, we should can use it in the code file.

                Hope this helps

                Best regards,
                Jeffrey Tan
                Microsoft Online Partner Support
                Get Secure! - www.microsoft.com/security
                This posting is provided "as is" with no warranties and confers no rights.

                Comment

                • Stacey

                  #9
                  Re: Problems accessing configuration file in .NET 2.0

                  That did it.. thanks.
                  ""Jeffrey Tan[MSFT]"" <v-jetan@online.mi crosoft.com> wrote in message
                  news:6q7Bzhi%23 FHA.1240@TK2MSF TNGXA02.phx.gbl ...[color=blue]
                  > Hi Stacey,
                  >
                  > Thanks for your feedback.
                  >
                  > No, we should not add a new Settings.settin gs file. We should use the
                  > default Settings.settin gs file to store the application/user config data.
                  > Then VB.net20005 designer will associate them in My.Settings class.
                  >
                  > To use the default Settings.settin gs file, we can right click Project node
                  > in the solution explorer, then choose the "Properties " to open the
                  > "Project
                  > Properties" tab. Then we can click "Settings" tab in the "Project
                  > Properties" tab. At last, we can set the config data in the designer.
                  >
                  > After this, we should can use it in the code file.
                  >
                  > Hope this helps
                  >
                  > Best regards,
                  > Jeffrey Tan
                  > Microsoft Online Partner Support
                  > Get Secure! - www.microsoft.com/security
                  > This posting is provided "as is" with no warranties and confers no rights.
                  >[/color]


                  Comment

                  • Jeffrey Tan[MSFT]

                    #10
                    Re: Problems accessing configuration file in .NET 2.0

                    You are welcome

                    Best regards,
                    Jeffrey Tan
                    Microsoft Online Partner Support
                    Get Secure! - www.microsoft.com/security
                    This posting is provided "as is" with no warranties and confers no rights.

                    Comment

                    Working...