WCF 服务作为 Windows 服务的问题 (Windows 7)
我按照此处的步骤制作我现有的 WCF 服务(作为控制台应用程序已经可以正常工作),在我的 Windows 7 计算机(也是我的开发计算机)上也可以是 Windows 服务。
无论我尝试什么,在执行使用 installutil 的最后一步时,我都会在命令行中收到以下消息:
初始化安装时发生异常:
System.BadImageFormatException:无法加载文件或程序集“file:///[此处的路径]”或其依赖项之一。
尝试加载格式不正确的程序..
我的控制台应用程序主类继承自 ServiceBase
并实现 OnStart
和 OnEnd
方法。
我添加了从 System.Configuration.Install.Installer
继承的 ProjectInstaller
类,标记有 [RunInstaller(true)]
属性以及它们提供的代码在构造函数中。
我已经尝试过的内容在上面的文章中没有提到?
- 以管理员身份运行命令
- 行导航到 EXE 文件所在的目录并运行 installutil 为
- EXE 文件及其使用的所有 DLL 提供强密钥
另外,即使使用 /LogFile=myLog.txt
指定它,我也没有得到任何日志文件。
欢迎任何想法,谢谢。
I followed the steps here to make my existing WCF service (already working fine as console application) be Windows Service as well, on my Windows 7 machine which is also my development machine.
No matter what I tried, when doing the last step of using installutil, I'm getting the following message in the command line:
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///[path here]' or one of its dependencies.
An attempt was made to load a program with an incorrect format..
I have my console application main class inherit from ServiceBase
and implement OnStart
and OnEnd
methods.
I have added ProjectInstaller
class inheriting from System.Configuration.Install.Installer
marked with [RunInstaller(true)]
attribute and with the code they supplied in the constructor.
What I already tried that is not mentioned in the above article?
- Running the command line as administrator
- Navigating to the directory where the EXE file is located and running
installutil from there - Giving strong key to the EXE file and all DLL's it's using
Also, I don't get any log file even when specifying it with /LogFile=myLog.txt
.
Any ideas are welcome, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是 32 位/64 位问题。
您的机器是 64 位 Windows 7 吗?您的服务是否以某种方式引用了 32 位的内容,例如旧的 COM 组件或其他内容?
您可能需要在 Visual Studio 中使用 x86 平台编译您的内容才能使其正常工作...
That smells like a 32-/64-bit problem.
Is your machine 64-bit Windows 7 by any chance?? Does your service somehow reference something 32-bit , like an old COM component or something??
You might need to compile your stuff with the x86 platform in Visual Studio to get it to work properly...
BadImageFormat 异常通常在旧版本的 .NET 框架(没有 4.0 的计算机上的 4.0 程序集)中加载程序集时发生。由于您在同一台计算机上进行部署,我的猜测是您没有使用正确版本的 installutil。
确保您使用位于此处的 installutil:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
BadImageFormat exceptions usually occur when the assembly is loaded in an older version of the .NET framework (4.0 assembly on a machine without 4.0). Since you are deploying on the same machine, my guess would be that you are not using the correct version of installutil.
Make sure you use the installutil located here :
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319