簡體   English   中英

在TeamCity上運行NUnit測試時拋出BadImageFormatException

[英]BadImageFormatException thrown when running NUnit tests on TeamCity

我使用.Net 4.5使用NUnit 2.6.3進行單元測試項目。 但是在teamcity構建步驟配置中我只有運行時4.0可用(即使我的解決方案的其他組件是針對4.5編譯的),當我運行單元測試時,我得到以下異常:

    [Step 8/9] System.ArgumentException: Specified NUnit error running tests in '[SANITIZED].UnitTest.dll' assembly
Loading assembly is compiled for v4.0.30319, MSIL
NUnit runner runtime is v4.0.30319, x64
System.ArgumentException: A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context. ---> System.BadImageFormatException: Could not load file or assembly '[SANITIZED]' or one of its dependencies. An attempt was made to load a program with an incorrect format.
   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[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   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, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.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 JetBrains.TeamCity.NUnitLauncher.NUnitRunner.LoadTest(String testAssembly, String testName, TestRunner runner) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnit-2.6\NUnitRunner.cs:line 53
   at JetBrains.TeamCity.NUnitLauncher.AssemblyTest.LoadTestDomain() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\AssemblyTest.cs:line 76
   at JetBrains.TeamCity.NUnitLauncher.LoadTestDomainAction.Action(AssemblyTest test) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\LoadTestDomainAction.cs:line 17
   at JetBrains.TeamCity.NUnitLauncher.TryOneAssemblyTest.Action() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssemblyTest.cs:line 18
   at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssembly.cs:line 36
Check correct .NET Framework version and process platform (x64, x86, MSIL) are used both in the test runner settings and involved assemblies on this machine. description. description should be non-null string of (0, 4000] size
   at JetBrains.BuildServer.CommonLoggers.Impl.BuildProblemServiceMessageImpl.AddBuildProblem(String identity, String type, String description) in c:\BuildAgent\work\42f5b4bce579465c\src\CommonLoggers\src\Impl\BuildProblemServiceMessageImpl.cs:line 43
   at JetBrains.TeamCity.NUnitLauncher.TryOneAssembly.Do() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\TryOneAssembly.cs:line 64
   at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.DoTry(TryOneAssembly aTry) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 53
   at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.RunOneAssembly(AssemblyTest test, ITestOrderingStrategy strategy, Boolean isRecentTestMode) in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 161
   at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.RunInternal() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 141
   at JetBrains.TeamCity.NUnitLauncher.NUnitRunnerBase.Run() in c:\BuildAgent\work\42f5b4bce579465c\src\NUnitLauncher\src\NUnitRunnerBase.cs:line 60

有什么想法幫我配置這些單元測試嗎?

根據stacktrace和NUnit發行說明,我的印象是問題在於NUnit 2.6.3定位v4.0平台。

它似乎更像是NUnit測試運行器的位數問題,在你的工作中是x64:

NUnit runner runtime是v4.0.30319,x64

如果您的MSIL編譯的測試程序集試圖加載某些x86庫或類似的,則可以拋出BadImageFormatException

只需更改TeamCity作業的配置以使用32位NUnit運行程序(.NET運行時v4.0,x86)即可解決此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM