无法加载文件或程序集 'DocumentDB.Spatial.Sql.dll' 或其依赖

问题描述:

之一,我们有3个项目:无法加载文件或程序集 'DocumentDB.Spatial.Sql.dll' 或其依赖

  • 类库(目标框架4.5)
  • Web应用程序(MVC)项目(目标框架4.5)
  • 的Web API项目(目标框架4.5.2)

最近开始Azure的宇宙DB(文件DB驱动程序)工作。所有的实现都是在API & Web App项目中使用的类库中完成的。

显然,Web应用程序工作正常,但REST API项目抛出一个错误:

Could not load file or assembly 'file:///API\bin\DocumentDB.Spatial.Sql.dll' or one of its dependencies. The module was expected to contain an assembly manifest. 
 

 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 

 
Exception Details: System.BadImageFormatException: Could not load file or assembly 'file:///D:\API\bin\DocumentDB.Spatial.Sql.dll' or one of its dependencies. The module was expected to contain an assembly manifest. 
 

 
Source Error: 
 

 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
 

 
Assembly Load Trace: The following information can be helpful to determine why the assembly 'file:///D:\API\bin\DocumentDB.Spatial.Sql.dll' could not be loaded. 
 

 

 
WRN: Assembly binding logging is turned OFF. 
 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
 
Note: There is some performance penalty associated with assembly bind failure logging. 
 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 
 

 
Stack Trace: 
 

 

 
[BadImageFormatException: Could not load file or assembly 'file:///D:\API\bin\DocumentDB.Spatial.Sql.dll' or one of its dependencies. The module was expected to contain an assembly manifest.] 
 
    System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 
 
    System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36 
 
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 
 
    System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102 
 
    System.Reflection.Assembly.LoadFrom(String assemblyFile) +34 
 
    WebActivator.PreApplicationStartCode.Start() in D:\Code\Bitbucket\WebActivator\WebActivator\PreApplicationStartCode.cs:11 
 

 
[InvalidOperationException: The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'file:///D:\API\bin\DocumentDB.Spatial.Sql.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] 
 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +613 
 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141 
 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102 
 
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +157 
 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531 
 

 
[HttpException (0x80004005): The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'file:///D:\API\bin\DocumentDB.Spatial.Sql.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] 
 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9942412 
 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90 
 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

现在,已经尝试了以下修订(没有成功):

  1. 将API目标框架更改为4.5,重新启动 - 仍然是相同的错误。
  2. 清理解决方案,重建 - 仍然是相同的错误
  3. dll DocumentDb.Spatial.Sql.dll是相同的Web应用程序& Web API项目。

Could not load file or assembly 'file:///API\bin\DocumentDB.Spatial.Sql.dll'

此路径是可疑的。您必须检查哪个模块试图加载此dll(以及为什么)

尝试启用程序集绑定日志记录并在加载解决方案时检查错误。要启用日志记录本粘贴到txt文件(和更改扩展名为.reg):

Windows Registry Editor Version 5.00 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion] 
"ForceLog"=dword:00000001 
"LogFailures"=dword:00000001 
"LogResourceBinds"=dword:00000001 
"LogPath"="C:\\FusionLog" 

之后,支票夹C:\ FusionLog和搜索该DLL DocumentDB.Spatial.Sql.dll)

+0

我在发布问题之前编辑了文件路径。所以路径就像D:\ API \ bin \ DocumentDB.Spatial.sql.dll。抱歉误导,也会更新这个问题。 尽管如此,尝试了reg编辑文件,所有条目也在注册表中更新,但是没有可用的日志。 – Vikram

+0

对不起,我忘了补充一点,创建这个reg文件后 - 你必须双击它并允许输入注册表修改。你做到了吗? – Piotr

+0

是的,已经这样做了,最后它开始捕获信息。 日志:大会下载成功。尝试安装文件:D:\ API \ bin \ DocumentDB.Spatial.Sql.dll 日志:进入下载缓存设置阶段。 ERR:从文件中提取清单导入时出错(hr = 0x80131018)。 错误:安装失败,hr = 0x80131018。 ERR:无法完成程序集的设置(hr = 0x80131018)。探测终止。 ***装订文件夹日志条目(2017/8/4 @ 9:20:43 AM)*** 操作失败。 绑定结果:hr = 0x80131018。没有可用的描述。 – Vikram