首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >服务中的BadImageFormatException

服务中的BadImageFormatException
EN

Stack Overflow用户
提问于 2012-06-21 23:01:28
回答 1查看 1.3K关注 0票数 1

我有一个应用程序,这是一个长期运行的服务,我最近重写了它,使用插件和应用程序域来解决一个内存问题,原来不是我的问题,而是微软DirectoryServices命名空间中的泄漏,没有正确地处理东西。在我重写后,我不能再将应用程序作为服务运行,尽管它在控制台模式下运行得很好。尝试启动应用程序时,在windows事件日志中出现以下异常:

代码语言:javascript
复制
Application: ADImport.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.BadImageFormatException
Stack:
   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.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.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at ADImportPlugIn.LoadAssemblyAttributesProxy.LoadAssemblyAttributes(String assFile)
   at ADImportPlugIn.LoadAssemblyAttributesProxy.LoadAssemblyAttributes(System.String)
   at ADImportPlugIn.PlugInLoader.GetAssemblyNames()
   at ADImportPlugIn.PlugInLoader.LoadAllPlugIns()
   at ADImport.Program.WorkerMethod()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

我在这里进行了搜索,看到了许多关于应用程序的位数以及应用程序和相关DLL/程序集之间可能不匹配的线程。我已经检查了所有东西,尝试针对特定的平台等,似乎没有什么工作。我的开发平台是64位Windows 7,目标是Windows 2008 64位。我的应用程序设置为x86,我的程序集是任何the,尽管我尝试过将它们设置为x86、x64等。我在我的一个DLL中使用log4net,但我认为这不是问题所在。

任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2012-06-22 00:33:52

如上所述,我在过滤,但做错了。我有一个程序集正在使用

代码语言:javascript
复制
string[] fileNames = Directory.GetFiles(Environment.CurrentDirectory, "*.dll");

我需要将其更改为:

代码语言:javascript
复制
string[] fileNames = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

忘记这是一项Windows服务,当前目录不是应用程序的安装位置,而是Windows\System32的安装位置。多伊尔。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11141004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档