我遇到了运行时错误,我的控制台应用程序(VS2012)引用了" dcasdk.dll"。 控制台应用程序的.Net框架是4.5,平台目标是"任何CPU"。
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也是使用"任何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,我无法将其重新编译到任何特定平台。请分享您对此处可以做些什么的想法..
请注意我在Windows7,64位操作系统上运行此控制台应用程序。
*** 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.
如果我设置"首选32位"开,然后上面的错误消失。但是我仍然得到" FileNotFoundException","无法加载文件或程序集' dcasdk.dll'或其中一个依赖项。找不到指定的模块。"。但这次Fusion日志没有错误!
*** 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异常"栈跟踪..
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()
ISSUE并修复:
原来是dcasdk dll的依赖关系未被发现的问题。我确实联系了第三方提供商,他们确认dcasdk dll依赖于另外两个dll(稍后由他们提供),这些dll在添加后解决了问题!
感谢大家帮助我理解这个问题。
当我尝试将其部署为在Windows服务器R2上运行的计算机中的Windows服务时,我再次收到FileNotFoundException。
我尝试使用"首选32"导致了#34; BadImageFormatException"。
如果我使用x86平台目标进行编译,我将获得FileNotFoundException,尽管所需的所有dll都存在于服务文件夹中。
有人可以帮助我了解部署出了什么问题。它可以在预期的开发系统中使用"任何CPU,首选32位ON"。
答案 0 :(得分:6)
如上所述,这也是由于错误的架构造成的 a)在Windows x86中使用x64程序集 b)将x86程序集与x64进程一起使用或反之亦然
为了获得最佳效果,请确保所有.NET程序集都使用“Any CPU”和相同的.NET配置文件构建(即所有.NET程序集都使用.NET Core,或Client Profile或Full .NET)。
...或者根本找不到一个依赖项,启用Fusion Log以告知收集程序集的位置:
参见How to enable assembly bind failure logging (Fusion) in .NET 和 http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx
更新:鉴于错误代码0x8007000b,我很确定架构不匹配: a)dll可能是完整的.NET代码,但不能用AnyCPU编译 b)dll可能是本机代码,然后你需要一个匹配的架构(加上一些使用PInvoke调用它的代码) c)dll可能是C ++ CLI(本机/ .NET代码的混合,同样具有错误的架构)。 d)dll可能已损坏。
您可能需要与第三方提供商联系以获取支持。 此外,此链接提到它可能是.NET版本的不匹配。
无论如何,看起来问题已经缩小了。
此外,如果DLL部分是原生的,则可能需要MSVC运行时(正如此问题的答案提及,Using 32-bit dll on 64-bit system shows 0x8007000B Error)
在这种情况下,问题将是dcasdk未被发现的依赖性。 您可以查看哪个Dependency Walker,请参阅http://www.dependencywalker.com/ (它还有一个配置文件模式,您可以在其中分析exe,并查看打开在运行时失败的DLL的调用)。
答案 1 :(得分:0)
答案 2 :(得分:0)