您的位置:首页 > 其它

一个Visual Studio2010的bug….

2011-12-23 11:36 337 查看
今天发现一个VisualStudio2010的bug。是这样的,VS中Project属性有一项是关于Hosting Process的,如果我关闭这个选项,bug就出来了….





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

[code] AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", newCfgFile);

[/code]

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


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


[code] private void Form1_Load(object sender, EventArgs e)


{


string newCfgFile = @"C:\2.cfg";


 


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


 


this.textBox1.Text = ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString;


}

[/code]

程序App.config内容如下:


[code] <?xml version="1.0"?>


<configuration>


<connectionStrings>


<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="/>


</connectionStrings>


</configuration>

[/code]

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


[code] <?xml version="1.0"?>


<configuration>


<connectionStrings>


<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="/>


</connectionStrings>


</configuration>

[/code]

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


PS: 不知道哪位大侠遇到过,似乎MSDN上有关Visual Studio Hosting Process的信息很少很少。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: