无法加载文件或程序集'DocumentDB.Spatial.Sql'或其某个依赖项。

3
我已经将所有的NuGet包更新到最新版本。在本地调试或发布模式下,一切都很正常,但是一旦我发布到Azure上,网站主页就会出现以下问题:
[FileLoadException: Could not load file or assembly 'DocumentDB.Spatial.Sql' or one of its dependencies. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)]
   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.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +457
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'DocumentDB.Spatial.Sql' or one of its dependencies. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +729
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +247
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +157
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +321
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +878

[HttpException (0x80004005): Could not load file or assembly 'DocumentDB.Spatial.Sql' or one of its dependencies. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +124
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +700

这些是已安装的Nuget包:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="3.2.1" targetFramework="net452" />
  <package id="Microsoft.AspNet.SignalR" version="2.2.2" targetFramework="net452" />
  <package id="Microsoft.AspNet.SignalR.Core" version="2.2.2" targetFramework="net452" />
  <package id="Microsoft.AspNet.SignalR.JS" version="2.2.2" targetFramework="net452" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="2.2.2" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.Azure.DocumentDB" version="1.18.0" targetFramework="net452" />
  <package id="Microsoft.Azure.DocumentDB.ChangeFeedProcessor" version="1.2.0" targetFramework="net452" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.8" targetFramework="net452" />
  <package id="Microsoft.Net.Compilers" version="2.4.0" targetFramework="net452" developmentDependency="true" />
  <package id="Microsoft.Owin" version="4.0.0-alpha1" targetFramework="net452" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="4.0.0-alpha1" targetFramework="net452" />
  <package id="Microsoft.Owin.Security" version="4.0.0-alpha1" targetFramework="net452" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
  <package id="Owin" version="1.0" targetFramework="net452" />
</packages>

发布构建日志:
1>------ Publish started: Project: redacted, Configuration: Release Any CPU ------
1>Transformed Web.config using C:\Projects\redacted\redacted\Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.
1>Auto ConnectionString Transformed obj\Release\TransformWebConfig\transformed\Web.config into obj\Release\CSAutoParameterize\transformed\Web.config.
1>Copying all files to temporary location below for package/publish:
1>obj\Release\Package\PackageTmp.
1>Start Web Deploy Publish the Application/package to https://redacted.scm.azurewebsites.net/msdeploy.axd?site=redacted ...
1>Adding ACLs for path (redacted)
1>Adding ACLs for path (redacted)
1>Updating file (redacted\bin\DocumentDB.Spatial.Sql.dll).
1>Updating file (redacted\bin\redacted.dll).
1>Updating file (redacted\bin\Microsoft.Azure.Documents.Client.dll).
1>Updating file (redacted\bin\Microsoft.Azure.Documents.ServiceInterop.dll).
1>Updating file (redacted\packages.config).
1>Updating file (redacted\Web.config).
1>Adding ACLs for path (redacted)
1>Adding ACLs for path (redacted)
1>Publish Succeeded.
1>Web App was published successfully http://redacted.azurewebsites.net/
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

在构建过程中,您可以看到目标DLL被添加到软件包中。
我无法将其从此状态中移出 - 它在开发服务器上,现在我的前端开发人员变得焦虑了。
我尝试回滚DocumentDB,但没有帮助。这是在我不情愿地决定更新nuget包之后发生的。
看起来DocumentDB.Spatial.Sql.dll文件甚至不是.net程序集。为什么它要尝试将其作为这样的程序加载?它只是一个本机64位DLL。
这是我在Azure网站上部署的项目的图像: enter image description here

你的 bin 目录里有 SqlServerTypes 目录吗? - Ramy M. Mousa
@RamyMohamed -- 我添加了一个网站FTP列表的图像。那个目录不在那里。 - Andy
请尝试安装 Microsoft.SqlServer.Types 包,然后重新构建和发布。 - Ramy M. Mousa
@RamyMohamed -- 那不行。它在 DocumentDB.Spatial.Sql 上失败,而不是 SQLServerSpatial。 - Andy
@RamyMohamed -- 感谢你尝试帮助我。问题出在发布工具上。我通过FTP手动删除了BIN目录中的所有文件。然后从我的本地目录手动上传到网站,这样就可以正常工作了。因此,发布工具缺少某些东西。 - Andy
1个回答

3
如果有其他人遇到类似的问题,那么这是发布工具的一个错误。我解决这个问题的方法如下:
  1. 更新你所有的Nuget packages
  2. 关闭Visual Studio
  3. 删除你本地的project\binproject\obj目录
  4. 打开Visual Studio并重新生成RELEASE包
  5. 转到Azure网站并停止应用程序
  6. 打开FTP客户端,连接您的网站
  7. 删除/site/wwwroot/bin目录中的所有文件
  8. 手动上传project\bin目录中的所有文件到/site/wwwroot/bin目录
  9. 启动你的Azure网站
这些步骤使我的一切正常了。我认为有些旧的Nuget packages可能会导致冲突,所以在更新Nuget packages之后,这些步骤可以确保你的生产网站以干净的状态开始运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接