Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 引用的程序集无法读取app.config_C#_Unit Testing_Sitecore_Appsettings - Fatal编程技术网

C# 引用的程序集无法读取app.config

C# 引用的程序集无法读取app.config,c#,unit-testing,sitecore,appsettings,C#,Unit Testing,Sitecore,Appsettings,我的单元测试有问题。问题是:我正在使用Sitecore。我问的另一个问题是: 我的问题是我得到了一个例外: Test method foo.Bar.Framework.Tests.Core.UnitTest1.TestMethod1 threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Syst

我的单元测试有问题。问题是:我正在使用Sitecore。我问的另一个问题是:

我的问题是我得到了一个例外:

Test method foo.Bar.Framework.Tests.Core.UnitTest1.TestMethod1 threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Sitecore.Services.Heartbeat' threw an exception. ---> System.InvalidOperationException: Could not read Sitecore configuration.
我用dotPeek查看了代码,函数Sitecorre.Configuration.Settings.GetSetting(“HeartbeatInterval”)抛出了一个异常。因为它无法读取配置。 当我将相同的代码添加到unit test.cs文件并调试测试时,它可以读取配置。 app.config中也提供了该设置

看起来引用的程序集无法读取配置,测试本身也可以。 我怎样才能解决这个问题

编辑

Settings.GetSetting()函数最终使用Sitecore.Configuration.ConfigReader.GetConfigNode()。此函数最终使用此函数:

private static ConfigReader GetReader()
{
    return ConfigurationManager.GetSection("sitecore") as ConfigReader;
}
所以。。。
为什么引用的dll不能通过ConfigurationManager读取app.config?

结果是*.testsettings。
当我在pc上运行它时,它工作了,但在构建服务器上却没有。原来我只需要提交*.testsettings并包含/testsettings参数

您的app.config是在测试项目中还是在其他项目中?它在测试项目中。构建操作:无。复制到输出目录:不复制。程序集位于References文件夹中,显然它是否与常规项目一起工作?是的,我在web.config中获得了相同的设置,代码项目工作正常。可能异常意味着它已找到,但由于语法错误而不可读。请尝试删除该节并重新生成。你也有同样的例外吗?