Referenced assembly can not read app.config

↘锁芯ラ 提交于 2019-12-25 05:07:02

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/11517214/referenced-assembly-can-not-read-app-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!