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中该怎么样读取配置文件中的信息?

  • 相关阅读:
    网站运维之 优化
    网站运维之 风险防控
    网站运维之 使用IIS日志分析器1.03.exe进行IIS服务器日志分析
    MySQL数据库优化
    深入理解Java GC
    深入理解React虚拟DOM
    深入理解new String()
    深入理解JVM内存模型
    MySQL的四种事务隔离级别
    Node.js Stream(流)
  • 原文地址:https://www.cnblogs.com/JLL/p/204730.html
Copyright © 2011-2022 走看看