visual C# 2005 express beta2读配置文件的问题(ms的bug?)

visual C# 2005 express beta2读配置文件的问题:

app.config
-----------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
 
<configSections>
  
<sectionGroup name="mySectionGroup">
   
<section name="mySection"
      type
="System.Configuration.DictionarySectionHandler" />
  
</sectionGroup>
 
</configSections>
 
<mySectionGroup>
  
<mySection>
   
<add key="key1" value="value1" />
  
</mySection>
 
</mySectionGroup>
</configuration>


读取配置文件的程序(在项目中需要手动添加System.configuration的引用):
using System;
using System.Collections.Generic;
using System.Text;

using System.Collections.Specialized;
using System.Configuration;

namespace ConsoleApplication2
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            
try
            
{
                NameValueCollection ns 
= (NameValueCollection)ConfigurationManager.GetSection("mySectionGroup/mySection");
                
string s = ns["key1"];
                
int n = Convert.ToInt32(ns["key2"]);
                Console.WriteLine(s 
+ "" + n.ToString());
            }

            
finally
            
{
                Console.Read();
            }

        }

    }

}


结果执行老是出现异常,在vs2k3里这样的代码运行都很正常的!
请问:在2005中该怎么样读取配置文件中的信息?

原文地址:https://www.cnblogs.com/JLL/p/204730.html