2011-08-04 127 views
5

當我嘗試使用NUnit-console.exe運行在一個解決方案文件中的所有測試,例如:運行NUnit控制檯導致System.IO.FileLoadException

nunit-console.exe MyProject.sln

我得到以下異常(如下所示)。但是,在我的文件夾結構中的任何項目上運行控制檯運行程序時,運行程序工作正常,並且從不給我以下例外。我也非常確定,我鏈接到的nunit庫的版本與我使用的跑步者相同。另外,我的解決方案不參考包含我的.sln文件的目錄結構之外的任何項目。

有沒有人有任何線索我可以做什麼!? :(

謝謝! 菲爾

NUnit version 2.5.10.11092 
Copyright (C) 2002-2009 Charlie Poole. 
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. 
Copyright (C) 2000-2002 Philip Craig. 
All Rights Reserved. 

Runtime Environment - 
    OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1 
    CLR Version: 4.0.30319.1 (Net 4.0) 

ProcessModel: Default DomainUsage: Default 
Execution Runtime: net-4.0 
Unhandled Exception: 
System.IO.FileLoadException: Could not load file or assembly 'nunit.framework, Version=2.5.10.11092, Culture=neutral, Pu 
blicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the 
assembly reference. (Exception from HRESULT: 0x80131040) 
File name: 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' 

Server stack trace: 
    at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, 
IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) 
    at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInsta 
ntiationContext, RuntimeTypeHandle[] methodInstantiationContext) 
    at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHa 
ndle[] methodInstantiationContext) 
    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethod 
Arguments) 
    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope 
, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilte 
rType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMeth 
odInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) 
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, 
Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecorate 
dTargetSecurityTransparent) 
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) 
    at NUnit.Core.CoreExtensions.InstallAdhocExtensions(Assembly assembly) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) 
    at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) 
    at NUnit.Core.TestSuiteBuilder.Build(TestPackage package) 
    at NUnit.Core.SimpleTestRunner.Load(TestPackage package) 
    at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
    at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
    at NUnit.Core.RemoteTestRunner.Load(TestPackage package) 
    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, 
Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) 
    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExec 
uteInContext) 

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.Util.TestDomain.Load(TestPackage package) 
    at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options) 
    at NUnit.ConsoleRunner.Runner.Main(String[] args) 

WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 

Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 

回答

4

嘗試使用Fusion Log Viewer,看看有什麼組件加載失敗,它會告訴你它不僅未能對什麼文件,但如果它試圖尋找那文件中。

+0

啊!這個工具很神奇!感謝佩德羅:)事實證明,我們正在使用第三方軟件,其中包括與我們的版本不同的nunit dll。而nunit在找到我們之前發現了這個dll。 由於我們不需要在這個第三方軟件上運行nunit,我們剛剛刪除了它們的dll版本。我很想知道是否有更好的解決方法,但現在,我很滿意。 – Phil

2

在我的情況nunit-console.exe沒有從web|app.config尊重大會重定向。除非你提供/domain=multiple

我的問題: EntityFrameworkTesting.Moq - >請求Moq,版本= 4.2.1409.1722

我已經引用了一個較新的程序集。

對我來說,解決是添加/domain=multiple參數。看到NUnit docs

於是我運行:

D:\tools\NUnit-2.6.4\bin\nunit-console.exe %SOLUTION_PATH%\Project.sln /config:Release /framework:net-4.0 /domain=multiple /xml=nunit-result.xml