Could not load file or assembly 'dcasdk, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
我使用了CorFlags应用程序来检查dll的目标平台。以下是详细信息..
Version : v4.0.30319
CLR Header : 2.5
PE : PE32
CorFlags : 16
ILONLY : 0
32BIT : 0
Signed : 0
根据上述信息,我认为dll也是使用“Any CPU”目标构建的。因此,它应该可以与具有相同目标平台的控制台应用程序一起工作。当我运行时不确定为什么会出现此错误。我还尝试将目标平台更改为x86,但会出现以下“FileNotFoundException”。我在反编译器中检查了dll的引用。它只显示System.Xml和System.Data。这些已经作为引用添加到控制台应用程序中了。
Could not load file or assembly 'dcasdk.dll' or one of its dependencies. The specified module could not be found.
非常感谢任何关于此事的帮助。
提前致谢。
下面是来自Fusion的程序集绑定日志,根据错误信息的最后三行,似乎这是一个与程序集平台有关的问题。但由于这是一个第三方dll文件,我无法将其重新编译为任何特定的平台。请分享您对此该怎么处理的想法。
请注意,我正在运行64位的Windows7控制台应用程序。
*** Assembly Binder Log Entry (4/26/2017 @ 8:31:08 AM) ***
The operation failed.
Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.vshost.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = dcasdk, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/ConsoleApplication3/ConsoleApplication3/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ConsoleApplication3.vshost.exe
Calling assembly : ConsoleApplication3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/ConsoleApplication3/ConsoleApplication3/bin/Debug/dcasdk.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\dcasdk.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: dcasdk, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null
ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).
ERR: Run-from-source setup phase failed with hr = 0x8007000b.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
如果我将 "Prefer 32-bit" 设为 ON,则上述错误会消失。但是我仍然会收到 "FileNotFoundException","无法加载文件或程序集 'dcasdk.dll' 或其某个依赖项。找不到指定的模块。"。但这次在融合日志中没有错误!
*** Assembly Binder Log Entry (4/26/2017 @ 9:57:53 AM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.vshost.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = dcasdk, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/ConsoleApplication3/ConsoleApplication3/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ConsoleApplication3.vshost.exe
Calling assembly : ConsoleApplication3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/ConsoleApplication3/ConsoleApplication3/bin/Debug/dcasdk.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\dcasdk.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: dcasdk, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\ConsoleApplication3\ConsoleApplication3\bin\Debug\dcasdk.dll.
LOG: Assembly is loaded in default load context.
"FileNotFoundException" stacktrace..
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args)
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()
问题及解决方法:
事实证明,出现了dcasdk dll的依赖项找不到的问题。我联系了第三方提供商,他们确认dcasdk dll有两个更多的dll依赖(稍后由他们提供),添加后解决了问题!
感谢大家帮助我了解这个问题。
当我尝试在运行Windows Server R2的计算机上部署它作为Windows服务时,我再次遇到FileNotFoundException。
我尝试使用"Prefer 32"编译,结果出现"BadImageFormatException"。
如果我使用x86平台目标进行编译,虽然所需的所有dll都存在于服务文件夹中,但仍会出现FileNotFoundException。
有人能帮我理解部署出了什么问题吗?它在开发系统中按预期工作,使用"Any CPU,Prefer 32位 ON"。