NUnit FileNotFoundException: System.Configuration

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

I want to run some acceptance tests using Watin and I get the following error when i try to open the test assembly in NUnit GUI:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Exception details:

System.IO.FileNotFoundException...  Server stack trace:     at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)    at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)    at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)    at System.Reflection.Assembly.Load(String assemblyString)    at System.UnitySerializationHolder.GetRealObject(StreamingContext context)    at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)    at System.Runtime.Serialization.ObjectManager.DoFixups()    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)    at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)  Exception rethrown at [0]:     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at NUnit.Core.TestRunner.Load(TestPackage package)    at NUnit.Core.ProxyTestRunner.Load(TestPackage package)    at NUnit.Util.ProcessRunner.Load(TestPackage package)    at NUnit.Util.TestLoader.LoadTest(String testName)

Everything worked just fine before I added a reference to System.Configuration in order to read the base url from the App.config

回答1:

It appears that the problem was the order of sections in the App.config file.

I first added the appSettings section first, but after I moved it down everything started working as it should again.

Here's the App.config content:

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <configSections>         <sectionGroup name="NUnit">             <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>         </sectionGroup>     </configSections>      <NUnit>         <TestRunner>             <add key="ApartmentState" value="STA"/>         </TestRunner>     </NUnit>      <appSettings>         <add key="BaseUrl" value="http://localhost/Test"/>     </appSettings> </configuration>


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