c# - 如何找到事件 app.config 文件的路径?

标签 c# .net nunit app-config configurationmanager

我正在尝试完成这个异常处理程序:

if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null)
{
    string pathOfActiveConfigFile = ...?
    throw new ConfigurationErrorsException(
       "You either forgot to set the connection string, or " +
       "you're using a unit test framework that looks for  "+
       "the config file in strange places, update this file : " 
       + pathOfActiveConfigFile);
}

这个问题似乎只发生在我使用 nUnit 的时候。

最佳答案

试试这个

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

关于c# - 如何找到事件 app.config 文件的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793657/

相关文章:

C# - 如何将单个 Excel 工作表从一个工作簿复制到另一个工作簿?

c# - MySQL Entity Framework 在尝试添加时抛出异常

c# - .NET 单元测试项目组织

unit-testing - 使用 FakeItEasy 模拟 SUT 的内部调用

c# - 按命名空间并行运行 ReSharper 测试

c# - 从剪贴板复制增强型图元文件并将其另存为图像

c# - PostMessage 参数从 32 位 C# 到 64 位 C++

c# - 在C#中使用Entity Framework读取Oracle数据连接

c# - 从对象创建 Xml 文件

c# - 如何将任何对象序列化为字符串?