我是一位C#新手,他在2010年编写了一个使用第三方托管程序集(EncryptionManager.DLL)加密/解密数据的2010年C#程序。 程序在安装了.Net 3.5 SP1的XP Pro SP3中运行良好。 在Windows 7专业版64位启用了.NET 3.5,计划失败,出现以下错误:第三方加密托管程序集不会在Windows 7 Pro x64中加载
System.BadImageFormatException: Could not load file or assembly 'EncryptionManager, Version=1.0.2978.16361, Culture=neutral, PublicKeyToken=53b6ffdb4dc98f0f' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'EncryptionManager, Version=1.0.2978.16361, Culture=neutral, PublicKeyToken=53b6ffdb4dc98f0f'
DLL安装在GAC,是在程序的搜索路径。
隐式加载DLL(引用编译)。
清单和DLL系统版本匹配:
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="EncryptionManager.dll" size="25896">
<assemblyIdentity name="EncryptionManager" version="1.0.2978.16361" publicKeyToken="53B6FFDB4DC98F0F" language="neutral" processorArchitecture="x86" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>qAxbPPkBK+n8/jtJ8pnjvJg/E2A=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
什么我需要做的,使在Windows 7上运行这个?
[DLL或可执行文件是作为64位程序集加载的,但它包含32位功能或资源。例如,它依靠COM互操作或在32位动态链接库中调用方法。 要解决此异常,请将项目的Platform目标属性设置为x86(而不是x64或AnyCPU)并重新编译。](http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx)或该页面上列出的其他建议之一。 – Will 2012-01-17 14:31:19
就是这样!非常感谢。编译为x86解决了问题 – 2012-02-02 19:25:32