引用的程序集不能读取app.config[英] Referenced assembly can not read app.config

本文是小编为大家收集整理的关于引用的程序集不能读取app.config的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

本文来自:IT宝库(https://www.itbaoku.cn)

我的设备测试有问题.问题是:我正在使用Sitecore.我问的另一个问题是:单元测试SiteCore licensemanager

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

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")研究了代码.因为它无法读取配置. 当我将相同的代码添加到我的单元测试.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参数

本文地址:https://www.itbaoku.cn/post/2353619.html

问题描述

I'm having problems with my unit tests. The problem is: I'm using Sitecore. Another question I asked about this is: Unit Testing Sitecore LicenseManager

My problem is that I get the exception:

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.

I looked into the code with dotPeek and the function Sitecorre.Configuration.Settings.GetSetting("HeartbeatInterval") throws an exception. Because it can not read the configuration. When I add the same code to my unit test .cs file and debug the test it can read the configuration. The setting is also available in the app.config

It looks like the referenced assembly cannot read the config and the test itself can. How can I fix this?

EDIT

The Settings.GetSetting() function eventually uses Sitecore.Configuration.ConfigReader.GetConfigNode(). This Function eventually uses this function:

private static ConfigReader GetReader()
{
    return ConfigurationManager.GetSection("sitecore") as ConfigReader;
}

So... Why can't the referenced dll read the app.config through the ConfigurationManager?

推荐答案

It turned out to be the *.testsettings. When I ran it on my pc it worked but on the build server it did not. Turned out I just had to commit the *.testsettings and include the /testsettings parameter