I've seen the ticket “Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies” by Harsh Gupta and I'm having the same problem but without those solutions working for me.
I have an web application including ImageMagick that is freshly installed on a new Windows Server 2012 instance (that we're migrating to from a Windows Server 2008 R2 instance). The application runs ok on Server 2008 and locally, but not on Server 2012.
I have rebuilt the project after upgrading Magick.Net from 6.8.7.502 to 7.0.7.300, in the hope that the .Net Standard / .Net Core support mentioned in the Readme, introduced in 7.0.6, would solve my problem, but to no avail. Before doing that, I had also installed VC++ 2012 and 2015 as Harsh Gupta mentioned in their accepted answer.
Despite all this, I'm still getting a "HTTP Error 500.0 - Internal Server Error" page, telling me:
Module: AspNetInitializationExceptionModule
Notification: BeginRequest
Handler: ExtensionlessUrlHandler-Integrated-4.0
Error Code: 0x00000000
Requested URL: [redacted]
Physical Path: [redacted, but correct]
Logon Method: Not yet determined
Logon User: Not yet determined
The Event log shows a Warning event from ASP.NET 4.0.30319.0 with an Event ID of 1310 and the following Stack trace:
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:
Looking in the webroot, the bin
folder does contain Magick.NET-x86.dll (and Magick.NET-Q16-x86.dll and Magick.NET-Q16-x86.Native.dll), and the IIS_IUSRs
group does have read access to these DLLs (and all the others).
While it is a 64-bit server, the AppPool does have Enable 32-bit applications set to True. Changing the AppPool's Managed Pipeline Mode from Integrated to Classic also has no effect. I do note, however, that the number of applications for the AppPool is listed as zero (despite the website's advanced settings dialog showing the correct AppPool name):
I am completely at a loss and we are behind schedule on the migration of this application now, so any suggestions would be gratefully received.
Thanks!
Edited to add: There is a little more information at ticket #107 on Github.
In a separate conversation on Github with the creator of ImageMagick, we eventually got to checking the version numbers of DLLs, which led us to realise that — as well as the expected files Magick.NET-Q16-x86.dll
and Magick.NET-Q16-x86-Native.dll
both at version 7.0.7.300
— there was also a file Magick.NET-x86.dll
that is version 6.8.7.502
.
Quoting Dirk Lemstra directly:
The
Magick.NET-x86.dll
file is an old file that should not be there. Can you remove that file and check if that resolves your issue? I apologize for not noticing this much earlier.You no longer need to install the C++ redistributable. The necessary libraries are statically linked which means that you don't need to install that anymore.
Removing that superfluous file has solved the problem. 🎉