【问题标题】:Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found无法加载文件或程序集“Magick.NET-x86.DLL”或其依赖项之一。指定的模块无法找到
【发布时间】:2018-03-01 23:11:18
【问题描述】:

我已经看到票 “Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies” by Harsh Gupta 并且我遇到了同样的问题,但没有这些解决方案适合我。

我有一个包含 ImageMagick 的 Web 应用程序,它新安装在新的 Windows Server 2012 实例(我们正在从 Windows Server 2008 R2 实例迁移到该实例)上。该应用程序在 Server 2008 和本地运行正常,但在 Server 2012 上运行不正常。

我在将 Magick.Net 从 6.8.7.502 升级到 7.0.7.300 后重建了项目,希望在 7.0.6 中引入的.Net Standard / .Net Core support mentioned in the Readme 可以解决我的问题,但无济于事。在此之前,我还安装了 VC++ 2012 和 2015,正如 Harsh Gupta 提到的 in their accepted answer

尽管如此,我仍然收到“HTTP 错误 500.0 - 内部服务器错误”页面,告诉我:

模块: AspNetInitializationExceptionModule
通知: BeginRequest
处理程序: ExtensionlessUrlHandler-Integrated-4.0
错误代码: 0x00000000
请求的 URL: [已编辑]
物理路径: [已编辑,但正确]
登录方法:尚未确定
登录用户:尚未确定

事件日志显示来自 ASP.NET 4.0.30319.0 的警告事件,事件 ID 为 1310 和以下堆栈跟踪:

Event code: 3008 
Event message: A configuration error has occurred. 
Event time: 9/20/2017 6:20:40 PM 
Event time (UTC): 9/20/2017 6:20:40 PM 
Event ID: 4775ecdb4601401ca30aa057f77ae78a 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: [redacted]
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: [redacted]
    Machine name: [redacted]

Process information: 
    Process ID: 5096 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\[redacted]

Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found.
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
   at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
   at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
   at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
   at System.Web.Compilation.BuildManager.ExecutePreAppStart()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)



Request information: 
    Request URL: [redacted] 
    Request path: / 
    User host address: [redacted]
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: IIS APPPOOL\[redacted]

Thread information: 
    Thread ID: 8 
    Thread account name: IIS APPPOOL\[redacted]
    Is impersonating: False 
    Stack trace:    at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
   at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
   at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
   at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
   at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
   at System.Web.Compilation.BuildManager.ExecutePreAppStart()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)


Custom event details: 

查看 webroot,bin 文件夹确实包含 Magick.NET-x86.dll(以及 Magick.NET-Q16-x86.dll 和 Magick.NET-Q16-x86.Native.dll)和 @ 987654329@ 组确实拥有对这些 DLL(以及所有其他 DLL)的读取权限。

虽然它是 64 位服务器,但 AppPool 确实将启用 32 位应用程序设置为 True。将 AppPool 的 Managed Pipeline ModeIntegrated 更改为 Classic 也没有效果。但是,我确实注意到,AppPool 的应用程序数量被列为零(尽管网站的高级设置对话框显示了正确的 AppPool 名称):

我完全不知所措,我们现在在迁移此应用程序方面落后于计划,因此我们将不胜感激地收到任何建议。

谢谢!

编辑添加:#107 on Github有更多信息。

【问题讨论】:

  • 您说这是一个新服务器,您是否尝试使用regiis 安装asp.net
  • @Webruster ASP.Net 已安装(使用服务器管理器中的角色和功能向导)。最初情况并非如此,因此我们(不出所料)看到了不同的错误消息。问题中的错误是在 ASP.Net 运行后才出现的。
  • 安装VC++ 2012后是否尝试重启服务器?
  • @Webruster 服务器不在生产环境中使用,所以我相信它会在一夜之间关闭(因此经常重启)。我现在将手动重新设置它,看看是否可以解决任何问题:)
  • @Webruster 我刚刚手动重启了它,并没有改变任何东西:(

标签: asp.net iis-8 assembly-loading imagemagick.net


【解决方案1】:

我没有答案,但有一些关于故障排除的想法,尽管您可能尝试过这些。

  1. 您提到应用程序池未显示应用程序。尝试重新创建应用程序池或使用预先存在的应用程序池之一作为临时选项,以查看应用程序池是否存在问题。
  2. 您正在使用我会使用的 apppool,这是最好的,但如果更改为网络服务帐户帮助,则表示权限问题。
  3. 您是否比较了新旧服务器上安装的 Windows 功能?只是想知道它是否需要 WCF。
  4. 是否在 iis 中赋予 bin 目录执行权限。
  5. 基本的 aspx 页面是否正常工作,或者配置是否也破坏了这些页面。

也许您已经尝试了所有这些,但希望它可以为您提供另一个方向,即使它没有直接帮助。

【讨论】:

  • 不高兴,恐怕。混淆应用程序池和权限并没有帮助。 WCF 未安装在旧服务器上,每个人都已经在 bin 文件夹上读取和执行,这是给我错误的主页。同一服务器上的另一个站点(不使用 ImageMagick)运行良好。
  • 对不起,我认为我没有正确解释 bin 目录的权限更改。我的意思是处理程序映射功能权限,因为这些可以设置为读取、脚本和执行,而不是文件夹的 NTLM 权限。我希望您需要启用 ISAPI-dll 处理程序映射: 1. 在 IIS 中,转到网站 bin 目录 2. 打开处理程序映射功能 3. 打开操作 -> 编辑功能权限。 4. 选择读取、脚本和执行
  • 要检查/比较的另一件事是 ISAPI 和 CGI​​ 限制,因为您经常需要在编辑功能设置链接中指定允许使用哪些 dll 或设置允许所有未指定的模块功能(注意这是在服务器级别设置的)。您还可以在 2 台服务器上比较站点级别的 ISAPI 过滤器功能。
【解决方案2】:

尝试使用Global Assembly Cache Tool (gacutil.exe) 将缺少的程序集发布到 GAC:

gacutil.exe /i Magick.NET-x86.dll /f
gacutil.exe /i Magick.NET-Q16-x86.dll /f 
gacutil.exe /i Magick.NET-Q16-x86.Native.dll /f

当.NET 运行时在本地路径中找不到项目引用的程序集时,它会扫描GAC 中的程序集。我们通常将 GAC 用于由多个应用程序共享的程序集,但我们可以尝试这种方法进行故障排除。

如果有问题的应用程序在将这些程序集发布到 GAC 后成功运行,则使用它们的项目中的程序集引用属性可能存在问题。

测试后,我们可以从 GAC 中删除我们添加的程序集:

gacutil.exe /u Magick.NET-x86 
...

gacutil.exe 附带 .NET Windows SDK。为了避免在服务器上安装这个,我们可以使用 PowerShell 来安装程序集:

[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") > $null
[System.EnterpriseServices.Internal.Publish] $publisher = new-object System.EnterpriseServices.Internal.Publish
$publisher.GacInstall('Path\To\Magick.NET-x86.dll')

这两个工具都需要服务器的管理员权限。

【讨论】:

  • 谢谢,赛。即使在将所有 3 个 ImageMagick DLL 安装到 GAC 之后,我仍然会在事件日志中显示相同的异常。我想我的下一步是使用Process Monitor,正如Michael Liu 建议的那样,找出哪个 依赖项失败了。感谢您的帮助!
  • (这是VC++运行时,肯定是安装的。更多细节在问题的评论线程中,回复Michael。)
  • @OwenBlacker 听起来像是进步!我看了看pastebin。你知道你安装的是哪个版本的vcredist包吗?我们正在尝试为 Magick 加载 x86 DLL,这可能需要 x86 VC++ 运行时(服务器可能只安装了 64 位版本)。
【解决方案3】:

In a separate conversation on Github 与 ImageMagick 的创建者一起,我们最终检查了 DLL 的版本号,这使我们意识到 - 以及预期的文件 Magick.NET-Q16-x86.dllMagick.NET-Q16-x86-Native.dll 都在版本 7.0.7.300 -还有一个文件Magick.NET-x86.dll,即版本6.8.7.502

直接引用Dirk Lemstra

Magick.NET-x86.dll 文件是不应存在的旧文件。您可以删除该文件并检查是否可以解决您的问题吗?很抱歉没有早点注意到这一点。

您不再需要安装 C++ 可再发行组件。必要的库是静态链接的,这意味着您不再需要安装它。

删除多余的文件已经解决了这个问题。 ?

【讨论】:

    猜你喜欢
    • 2014-06-12
    • 2014-12-04
    • 1970-01-01
    • 2018-10-26
    • 2023-03-15
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    相关资源
    最近更新 更多