1

I have an application that is a long running service, I recently re-wrote it to use plugins and appdomains to solve a memory issue which turned out not to be mine but a leak in Microsoft's DirectoryServices namespace not properly disposing stuff. After my re-write I can no tlonger run the application as a service though it runs fine in console mode. When attempting to start the application I get the following exception in the windows event log:

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()

I have searched on here and seen many threads about the bit-ness of the application and possible mis-matches between the application and associated DLLs/assemblies. I have checked everything, tried targeting specific platforms etc, nothing seems to work. My dev platform is 64bit Windows 7, target is Windows 2008 64bit. My application is set to x86, my assemplies are anycpu though I have tried setting them too x86, x64 etc. I am using log4net in one of my DLL's but don't think that's the issue.

Any help would be appreciated!

4

1 回答 1

0

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

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

我需要将其更改为:

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

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

于 2012-06-21T16:33:51.813 回答