Results 1 to 4 of 4

Thread: Conversion from VB.NET 2002 to VB.NET 2005 - Reading Configuration Files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Location
    Glasgow, Scotland
    Posts
    77

    Conversion from VB.NET 2002 to VB.NET 2005 - Reading Configuration Files

    I have just managed to persuade our company to invest in the Professional edition of Visual Studio 2005, to replace our existing installation of VS2002.

    I'm having a number of conversion issues, which are leaving me a bit confused. All of my applications are windows-based, are built using VB2002, and are built to read default settings from an XML configuration file.

    In the old days, I would "IMPORT" the System.Configuration library. From there, I would reference the appropriate config file setting using the following syntax:

    <variablename> = ConfigurationSettings.AppSettings("<SettingName>")

    However, when I try to compile an application that I've just converted from VS2002 to VS2005, I get the following error:

    'Public Shared Function GetConfig(sectionName As String) As Object' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection'

    However, when I try to alter the code, it throws up syntax errors. Can someone tell me what the correct code should be for this?
    Wise man once said: "Don't ever get married, just find a woman you don't like and buy her a house".
    According to ancient Chinese proverb, "Man with hole in pocket feels cocky all day".

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Conversion from VB.NET 2002 to VB.NET 2005 - Reading Configuration Files

    I don't understand how you can get syntax errors if you follow what Intellisense tells you. Have you read the MSDN help topic for the GetSection method? It specifically states that it returns the requested ConfigurationSection object. Have you read the MSDN help topic for the ConfigurationSection class and those classes derived from it. One of the derived classes is the AppSettingsSection. That sounds suspiciously like something useful. All the informnation you need is available in the MSDN library but it won't fall in your lap.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: Conversion from VB.NET 2002 to VB.NET 2005 - Reading Configuration Files

    This doesn't help with your question, but I got tired of seeing the "Windows Forms Designer Generated Code" region in my converted forms when 2005 uses a Partial Class to hold that type of information. If you are having the same issue, I wrote a quick little application to read through an imported solution and cleanup the code to make it look like 2005 code.

    You can find that app here if interrested. http://www.vbforums.com/showthread.php?t=376899

    PS - This was for converting 2003 to 2005, but there probably isn't much difference with 2002. The source code is included if you want to tweak it to better fit some of your solutions.

    PSS - As always, make a backup copy of your solution before running this app on it.
    My.Settings.Signature = String.Empty

  4. #4
    Lively Member bmilano's Avatar
    Join Date
    Jan 2005
    Location
    Broad Run, VA
    Posts
    126

    Re: Conversion from VB.NET 2002 to VB.NET 2005 - Reading Configuration Files

    I had the same problem when configuration settings when I converted my app. In VS 2003 I had:

    VB Code:
    1. strKey = AppSettings(strInputKey)

    and VS 2005 puked on it with the same error you got. I have no idea if this is the best way to do it, but I replaced the code with the following convoluted mess (I use strict typing), and it seems to work:

    VB Code:
    1. Dim myAppSettingsReader As New System.Configuratino.AppSettingsReader
    2.  
    3. strKey = CType(myAppSettingsReader.GetValue(strInputKey, GetType(String)), String)

    I'm sure there is a much cleaner way to deal with it, but I haven't yet taken the time to clean that up. Any suggestions would be appreciated.
    If you like my posts, please rate them so I can be somebody!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width