zoukankan      html  css  js  c++  java
  • 一个Visual Studio2010的bug….

    今天发现一个VisualStudio2010的bug。是这样的,VS中Project属性有一项是关于Hosting Process的,如果我关闭这个选项,bug就出来了….

    12-23-2011 11-28-26

    大家知道,.NET程序有个App.config/web.config,我现在把它重定向到另外一个位置的配置文件:

       1: AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", newCfgFile);

    这样重定向以后你用ConfigurationManager就会发现它会自动读取重定向的配置文件了。

    为了演示,建立一个简单的WindowForms程序,代码:

       1: private void Form1_Load(object sender, EventArgs e)
       2: {
       3:     string newCfgFile = @"C:\2.cfg";
       4:  
       5:     AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", newCfgFile);
       6:  
       7:     this.textBox1.Text = ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString;
       8: }

    程序App.config内容如下:

       1: <?xml version="1.0"?>
       2: <configuration>
       3:   <connectionStrings>
       4:     <add name="SqlServices" providerName="System.Data.SqlClient" connectionString="Persist Security Info=True;timeout=5;Data Source=127.0.0.1;Initial Catalog=abc;User ID=;Password="/>
       5:   </connectionStrings>
       6: </configuration>

    2.cfg内容(重定向的):

       1: <?xml version="1.0"?>
       2: <configuration>
       3:   <connectionStrings>
       4:     <add name="SqlServices" providerName="System.Data.SqlClient" connectionString="Persist Security Info=True;timeout=5;Data Source=127.0.0.2;Initial Catalog=abc;User ID=;Password="/>
       5:   </connectionStrings>
       6: </configuration>

    注意在debug模式下在VS2010中运行,如果我关闭”Enable Visual Studio Hosting Process”选项的话,取得的值就不对了。虽然重定向成功,但似乎ConfigurationManager还是读取老的配置文件。(如果不是在debug模式下在VS2010中运行,而是直接运行可执行文件*.exe,那就没有问题,所以可以断定是VS2010 debugger 的问题。)

    PS: 不知道哪位大侠遇到过,似乎MSDN上有关Visual Studio Hosting Process的信息很少很少。

  • 相关阅读:
    美赛 LaTeX 急救指南
    切比雪夫定理的证明
    【持续更新】一个简洁、易用的美赛 LaTeX 模板: easymcm
    一个形式较精细的 Strling 公式的证明
    数学分析的主线,高等数学的一切:连续函数与“有理”分析
    一个自己稍作修改了的美赛论文 LaTeX 模板
    有关几个特殊命题的证明
    实数系与实数定理(下)
    实数系与实数定理(上)
    Office365完整离线安装包下载及自定义安装教程
  • 原文地址:https://www.cnblogs.com/Mainz/p/2299168.html
Copyright © 2011-2022 走看看