无法加载文件或程序集“Magick.NET-x86.DLL”或其依赖项之一。找不到指定的模块

时间:2017-09-20 18:50:21

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

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

我有一个Web应用程序,包括新安装在新Windows Server 2012实例上的ImageMagick(我们正在从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 Error 500.0 - Internal Server Error”页面,告诉我:

  

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

事件日志显示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),以及IIS_IUSRs组确实具有对这些DLL(以及所有其他DLL)的读访问权。

虽然它是64位服务器,但AppPool确实将启用32位应用程序设置为 True 。将AppPool的托管管道模式集成更改为 Classic 也无效。但请注意,AppPool的应用程序数量列为零(尽管网站的高级设置对话框显示了正确的AppPool名称): Screenshot of AppPools

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

谢谢!

已编辑添加:在故障单#107 on Github上有更多信息。

3 个答案:

答案 0 :(得分:2)

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

  1. 您提到apppool未显示该应用程序。尝试重新创建apppool或使用其中一个预先存在的apppool作为临时选项,以查看apppool是否存在问题。
  2. 您正在使用apppool我,这是最好的,但确实会更改为网络服务帐户帮助,如果是这样,则指向权限问题。
  3. 您是否比较了旧服务器和新服务器上已安装的Windows功能?只是想知道它是否需要WCF。
  4. bin目录是否已在iis中执行perms。
  5. 基本的aspx页面是否有效,或者配置是否打破了这些。
  6. 也许你已经尝试了所有这些,但希望它可能有助于给你另一个方向,即使它没有直接帮助。

答案 1 :(得分:1)

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

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

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

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

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

[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')

gacutil.exe 随.NET Windows SDK一起提供。为避免在服务器上安装它,我们可以使用PowerShell安装程序集:

['D', 'G', 'F', 'H']

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

答案 2 :(得分:1)

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 ++可再发行组件。必要的库是静态链接的,这意味着您不再需要安装它。

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