简体   繁体   English

具有32位依赖项的64位WCF服务

[英]64-bit WCF Service with 32-bit dependencies

I have a WCF Service and a library, both being compiled for x64. 我有一个WCF服务和一个库,都针对x64进行了编译。 The library has some NuGet packages which "appear" to be 32-bit. 该库具有一些“看起来”为32位的NuGet软件包。 I get a System.BadImageFormatException when I try to run or publish the WCF Service but, oddly, I don't get any warnings about mismatching architectures. 当我尝试运行或发布WCF服务时,出现System.BadImageFormatException ,但奇怪的是,我没有收到有关体系结构不匹配的任何警告。

The full text of the error: Additional information: Could not load file or assembly 'Library' or one of its dependencies. An attempt was made to load a program with an incorrect format. 错误的全文: Additional information: Could not load file or assembly 'Library' or one of its dependencies. An attempt was made to load a program with an incorrect format. Additional information: Could not load file or assembly 'Library' or one of its dependencies. An attempt was made to load a program with an incorrect format.

As a test, I created a separate console application, added a reference to the library, made the architectures for both the console application and the library x64, and ran the console application. 作为测试,我创建了一个单独的控制台应用程序,添加了对该库的引用,为控制台应用程序和库x64制定了体系结构,并运行了控制台应用程序。 Same error. 同样的错误。

The WCF Service application will be hosted in IIS and is being debugged with the WCF Test Client. WCF服务应用程序将托管在IIS中,并且正在使用WCF测试客户端进行调试。

The NuGet packages I am using are these: 我正在使用的NuGet软件包是:

  • CsvHelper (Josh Close), v2.16.3 CsvHelper(立即关闭),v2.16.3
  • Newtonsoft.Json (James Newton-King), v9.0.1 Newtonsoft.Json(詹姆斯·牛顿·金),v9.0.1

I need to be able to run the service and library in 64-bit mode since I'm work with very large datasets, and need the extra RAM. 我需要能够以64位模式运行服务和库,因为我要处理非常大的数据集,并且需要额外的RAM。 My questions are 我的问题是

  • Is my problem that the NuGet packages are not compiled for x64? 我的问题是NuGet软件包没有针对x64编译吗?
  • How can I get this WCF service to run in this setup? 我如何才能在此设置中运行该WCF服务?

My problem was multi-part: 我的问题是多部分的:

  1. I did have to re-compile the libraries that I was using for x64. 我确实必须重新编译用于x64的库。 They had been compiled for Any CPU, which the runtime environment didn't like after loading an explicit x64 assembly. 它们是为任何CPU编译的,运行时环境在加载显式x64程序集后不喜欢这种CPU。
  2. DLL Hell DLL地狱
  3. IIS was running in 32-bit mode. IIS以32位模式运行。

First Issue: 首要问题:

I downloaded the source for the two libraries from GitHub and rebuilt for x64. 我从GitHub下载了这两个库的源代码,并针对x64进行了重建。 I added conditional compilation to the assembly references in the project files to facilitate switching back and forth between x64 and x86: 我将条件编译添加到项目文件中的程序集引用中,以方便在x64和x86之间来回切换:

<Reference Include="CsvHelper" Condition="'$(Platform)' == 'x86'">
  <HintPath>..\..\..\libraries\x86\CsvHelper\CsvHelper.dll</HintPath>
</Reference>
<Reference Include="CsvHelper" Condition="'$(Platform)' == 'x64'">
  <HintPath>..\..\..\libraries\x64\CsvHelper\CsvHelper.dll</HintPath>
</Reference>

To verify that my assemblies were actually x64, I found this answer very useful. 为了验证我的程序集实际上是x64,我发现此答案非常有用。 The utility can be run from the Visual Studio Developer Command Prompt . 该实用程序可以从Visual Studio开发人员命令提示符运行

Second Issue: 第二期:

Since I'm dealing with a large code base (42 projects), I had to do a complete clean to get rid of a x86 assembly that was getting copied around from ... somewhere. 由于我要处理大量的代码库(42个项目),因此我必须进行彻底清理才能摆脱从...某处复制的x86程序集。 Cleaning through Visual Studio didn't help; 通过Visual Studio进行清理无济于事; I had to clean my Git repository to get rid of all old DLLs. 我必须清理 Git存储库以摆脱所有旧的DLL。 Cleaning will only help this if your bin and obj folders are ignored by Git. 只有在您的bin和obj文件夹被Git忽略的情况下,清理才有帮助。

Third Issue: 第三期:

I (eventually) found this post (closing and reopening your project/solution/Visual Studio is also necessary after this step). 我(最终)找到了这篇文章(在此步骤之后,也有必要关闭并重新打开项目/解决方案/ Visual Studio)。 This setting can also be accessed as indicated here . 也可以按此处指示访问此设置。 After updating this setting, I had to restart IIS. 更新此设置后,我必须重新启动IIS。 Instructions for that are available on MSDN . 有关说明,请参见MSDN I will add that it might be helpful to first start a separate command prompt with elevated privileges before executing that command, otherwise the command prompt opened by the run window flashes into and out of existence too quickly to see what appeared in it. 我将补充说,在执行该命令之前先使用特权提升来启动一个单独的命令提示符可能会有所帮助,否则运行窗口打开的命令提示符会快速闪烁,而无法查看其中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM