我有一个使用c#和system.data.sqlite.dll x64构建的WCF服务库。构建配置是Any CPU。它工作正常。但是,当我将system.data.sqlite.dll更改为x86位版本时,对于任何CPU配置,它都会成功构建,但是当我运行wcf方法时,它会出错,对于x86构建配置,它会成功构建,但在我调试它时会出现以下错误使用wcftestclient。
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\lala\Desktop\New folder\New folder\CoreServiceWCF\CoreServiceWCF\CoreServiceWCF2\bin\x86\Debug\VplusCoreServiceWCF.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Users\lala\Desktop\New folder\New folder\CoreServiceWCF\CoreServiceWCF\CoreServiceWCF2\bin\x86\Debug\VplusCoreServiceWCF.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
=== Pre-bind state information ===
LOG: User = lala-PC\lala
LOG: Where-ref bind. Location = C:\Users\lala\Desktop\New folder\New folder\CoreServiceWCF\CoreServiceWCF\CoreServiceWCF2\bin\x86\Debug\VplusCoreServiceWCF.dll
LOG: Appbase = file:///C:/Users/lala/Desktop/New folder/New folder/CoreServiceWCF/CoreServiceWCF/CoreServiceWCF2/bin/x86/Debug
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:\Users\lala\Desktop\New folder\New folder\CoreServiceWCF\CoreServiceWCF\CoreServiceWCF2\bin\x86\Debug\VplusCoreServiceWCF.dll.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:/Users/lala/Desktop/New folder/New folder/CoreServiceWCF/CoreServiceWCF/CoreServiceWCF2/bin/x86/Debug/VplusCoreServiceWCF.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
有人帮我解决了这个问题吗?
答案 0 :(得分:0)
当为任何CPU构建程序集时,它将采用您运行的计算机的最佳配置,这意味着如果您有64位Windows,它将以64位模式运行,如果它是,则它将以32位模式运行在32位Windows中,问题似乎是这个程序集:VplusCoreServiceWCF.dll,所以我建议你先检查一下这个程序集的位数,看看它是否正确(在你的情况下可能是64位)
编辑:挖掘我发现WCF测试客户端只能以64位模式运行,因此您可能需要将其强制为32位,为此您可以在此处找到所需信息:I can't compile a standard "WCF Service Library" in x86 format