zoukankan      html  css  js  c++  java
  • 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中该怎么样读取配置文件中的信息?

  • 相关阅读:
    zw字王《中华大字库》2018版升级项目正式启动
    字王大藏经体v0.1概念版
    zw-clay字王胶泥体系列
    中文字库的造与创
    【转】Delphi+Halcon实战一:两行代码识别QR二维码
    zw.delphi不同版本程序运行速度测试
    《zw版·Halcon入门教程与内置demo》
    字王·百字工程·第一阶段纪念
    黑天鹅算法与大数据的四个层次
    zw版足彩大数据&报价
  • 原文地址:https://www.cnblogs.com/JLL/p/204730.html
Copyright © 2011-2022 走看看