1

我在加载 that.dll 时遇到问题,其中包含调用我的 work.dll 的测试类。

我可以用 helloworld.dll 很好地做到这一点,但是当我将 helloworld 测试放在我的 test.dll 中时,它无法加载,即使我从 test.dll 中删除了我的 work.dll 引用

我认为她的问题是 Fitness 不知道 work.dll 的路径,我该如何指定它?(最好在根页面中)

我收到的错误消息是:

System.BadImageFormatException: Could not load file or assembly 'file:///C:\Projects\..\test.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Projects\..\test.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at fitSharp.Machine.Engine.CurrentDomain.LoadAssembly(String assemblyPath)
   at fitSharp.Machine.Engine.ApplicationUnderTest.Assemblies.AddAssembly(String assemblyName)
   at fitSharp.Machine.Engine.ApplicationUnderTest.AddAssemblies(IEnumerable`1 assemblyNames)
   at fitnesse.fitserver.FitServer.ParseCommandLineArguments(IEnumerable`1 args)
   at fitnesse.fitserver.FitServer.Run(IList`1 CommandLineArguments)
   at fitnesse.fitserver.FitServer.Run(IList`1 commandLineArguments, Memory memory, ProgressReporter reporter)
   at fitSharp.Machine.Application.Shell.Run()
   at fitSharp.Machine.Application.Shell.Execute()
   at fitSharp.Machine.Application.Shell.Run(IList`1 commandLineArguments)

=== Pre-bind state information ===
LOG: User = kenneth
LOG: Where-ref bind. Location = C:\Projects\..\test.dll
LOG: Appbase = file:///C:/Projects/fitnesse/dotnet2/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Projects\fitnesse\dotnet2\Runner.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Projects/../test.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

有没有人有任何线索/提示。

谢谢肯尼斯

4

4 回答 4

3

您只能加载与应用程序进程位数相匹配的 DLL。这BadImageFormatException就是试图告诉你的,你试图加载一个不兼容的 DLL。

因此,如果您有 32 位 (x86) 进程,则只能加载 32 位 (x86) DLL。
如果您有 64 位 (x64) 进程,则只能加载 64 位 (x64) DLL。

“任何 CPU”编译器设置仅意味着进程的位数将匹配您机器的本机位数:在 64 位操作系统上为 64 位,否则为 32 位。

您将需要获取与应用程序位数相匹配的 DLL 版本,或者重新编译您的应用程序以针对不同的位数。

于 2013-07-23T09:56:58.047 回答
1

问题在于运行 64 位测试运行程序,并测试/加载 32 位 dll。为了解决这个问题,我在 TestRunner.exe 上运行了 CorFlags.exe,并设置了 /32BIT+ 标志。您可以从 SDK 获取 Corflags。

于 2013-07-26T07:32:28.103 回答
0

您是否查看了有关将代码添加到类路径的 FitSharp 说明:

于 2013-07-19T16:27:18.523 回答
0

根据 BadImageFormatException,您的 DLL 的 .net 版本与测试运行程序的 .net 版本之间似乎存在不匹配。

于 2013-07-19T16:41:52.157 回答