服务中的BadImageFormatException

问题描述 投票:1回答:1

我有一个应用程序是一个长期运行的服务,我最近重写它使用插件和appdomains来解决内存问题,结果不是我的,但微软的DirectoryServices命名空间泄漏没有正确处理东西。在我重新编写之后,我无法将应用程序作为服务运行,尽管它在控制台模式下运行良好。尝试启动应用程序时,我在Windows事件日志中得到以下异常:

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,我的声明是anycpu虽然我已经尝试设置它们x86,x64等。我在我的一个DLL中使用log4net,但不认为这是问题。

任何帮助,将不胜感激!

c# exception appdomain badimageformatexception
1个回答
0
投票

如上所述,我正在过滤,但做错了。我有一个正在使用的组件

string[] fileNames = Directory.GetFiles(Environment.CurrentDirectory, "*.dll");

我需要将其更改为:

string[] fileNames = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

忘记了,因为这是一个Windows服务,currentdirectory不是安装应用程序的地方,而是Windows \ System32。卫生署。

© www.soinside.com 2019 - 2024. All rights reserved.