C#服务将无法安装 [英] C# service will not install

查看:119
本文介绍了C#服务将无法安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取为安装而编写的服务,并在为任何CPU构建该服务时不断出现以下错误:

初始化安装时发生异常:
System.BadImageFormatException:无法加载文件或程序集;或其依赖项之一.试图加载格式错误的程序.


这只会在我的机器上发生.我的同事没有任何问题.如果我将其构建为32位,则在我的计算机上效果很好.它让我们感到困惑,我不确定开始寻找问题的最佳位置是我的电脑以外的地方.我尝试的一种解决方案是完全擦除,安装,更新等所有内容.

预先感谢您提供的帮助.

*编辑
我认为这与程序集无关,因为我的同事可以为任何CPU正常构建和运行它.问题似乎仅限于我使用的计算机.

I''m trying to get a service I''ve written to install and keep getting the following error when it is built for any CPU:

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly ''; or one of its dependencies. An attempt was made to load a program with an incorrect format..


This only happens on my machine. My co-worker has no issues on his. If I build it for 32 bit it works fine on mine. It''s has us stumped and I''m not sure where the best place to start looking for the problem is other than my computer. One solution I tried was a complete wipe, install, update, etc. of everything.

Thanks in advance for help provided.

*Edit
I don''t think it''s an issue with the assemblies because my co-worker can build and run it fine for any CPU. The problem seems limited to the machine I work on.

推荐答案

如果您的应用程序被编译为"AnyCPU",则它将始终仅在x64系统上作为x64进程运行.您只能在安装程序中安装x64依赖程序集(x86二进制文件永远不会在x64 OS上使用).您不能将它们混合.
您可能有一台x64机器,但是您的应用程序依赖于某些x86组件.如果您编译为x86,则所有标准都将具有相同的平台.
If your application is compiled as "AnyCPU", it will always run only as x64 process on x64 system. You can install only x64 dependent assemblies in your installer (the x86 binaries will never be used on x64 OS). You can not mix them.
You probably have an x64 machine, but your application depends on some x86 assamblies. If you compile to x86, all assamblies will have the same platform.


此处存在许多可能的问题,其中大多数与x86/x64问题有关.如果您有依赖于32位的dll,但尝试使用AnyCPU,则会收到此错误.如果在应用程序编译为32位时尝试使用64位安装程序,则会出现此错误.清单继续.这是几个堆栈溢出问题,提供了一些很好的答案和可能的解决方案:

http://stackoverflow.com/questions/323140/system-badimageformatexception-invalid-format-when-trying-to-install-service-w [ http://stackoverflow.com/questions/5229310/system-badimageformatexception-无法加载文件或程序集 [ ^ ]
There are a number of possible issues here, most of which revolve around the x86/x64 issue. If you have dlls that are 32-bit dependent but you try to use AnyCPU, you will get this error. If you try to use a 64-bit installer when the app compiles as 32-bit, you will get this error. The list goes on. Here are a couple Stack Overflow questions with some great answers and possible solutions:

http://stackoverflow.com/questions/323140/system-badimageformatexception-invalid-format-when-trying-to-install-service-w[^]

http://stackoverflow.com/questions/5229310/system-badimageformatexception-could-not-load-file-or-assembly[^]


这篇关于C#服务将无法安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆