2

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): Screenshot of AppPools

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.

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
  • as you are stating that this is a new server , did you tried to insall `asp.net` using `regiis`? – Krsna Kishore Sep 25 '17 at 03:21
  • @Webruster ASP.Net is installed (using the Roles and Features Wizard from Server Manager). That was not the case initially and we were (unsurprisingly) seeing a different error message as a result. The error in the question has only occurred since ASP.Net has been running. – Owen Blacker Sep 25 '17 at 07:47
  • did you tried to restart the server after installing the VC++ 2012 ? – Krsna Kishore Sep 26 '17 at 05:59
  • @Webruster The server is not in production use, so I believe it is shut down overnight (and, thus, rebooted often). I'll rebot it manually just now and see if that resolves anything :) – Owen Blacker Sep 26 '17 at 09:51
  • @Webruster I've just rebooted it manually now and that didn't change anything :( – Owen Blacker Sep 26 '17 at 10:40
  • go through this link https://blogs.iis.net/webtopics/troubleshooting-http-500-19-errors-in-iis-7 and verify any of that works for u – Krsna Kishore Sep 26 '17 at 12:10
  • @webruster Those are all 500.19 errors relaying to conduction file problems. We're seeing a 500.0 where it's failing to load a DLL. – Owen Blacker Sep 26 '17 at 13:02
  • from your edit you redacted on value , why is that ? another way to debug is to check all the Dlls from Server 2008 with your 2012 , then you can find a way what might be the issue... – Krsna Kishore Sep 27 '17 at 05:22
  • @Webruster The only things I've redacted are client names and domain names. – Owen Blacker Sep 28 '17 at 11:33
  • If possible, I would run [Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) locally on the Web server and see which DLL can't be found. – Michael Liu Sep 30 '17 at 04:08
  • @MichaelLiu Thank you. For some reason, it looks like it's the Visual C++ runtime not being found; [Procmon excerpt here](https://pastebin.com/2Jcnd9Yc) – Owen Blacker Oct 02 '17 at 09:40
  • And even copying `msvcp110.dll` into the `bin` folder doesn't help, despite [setting the permissions correctly](https://imgur.com/a/z21F2) – Owen Blacker Oct 02 '17 at 10:24

3 Answers3

2

I don't have an answer but a few ideas on troubleshooting, although you probably tried these.

  1. You mention the apppool isn't showing the application. Try recreating the apppool or using one of the preexisting apppools as a temporary option to see if there was an issue with apppool.
  2. You're using apppool I'd, which is best but does changing to network service account help, if so points at permission issue.
  3. Have you compared installed Windows features on the old and new servers? Just wondering if it requires WCF.
  4. Has the bin directory been given execute perms in iis.
  5. Do basic aspx pages work or is the configuration breaking those as well.

Maybe you've tried all that but hopefully it might help give you another direction, even if it doesn't help directly.

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
Andy B
  • 46
  • 2
  • No joy, I'm afraid. Messing with app-pools and permissions hasn't helped. WCF is not installed on the old server, Everyone already has Read & Execute on the `bin` folder and it's the homepage that is giving me the error. Another site on the same server (which doesn't use ImageMagick) is running fine. – Owen Blacker Sep 29 '17 at 15:16
  • Sorry, I don't think I explained the permissions change on the bin directory correctly. I was meaning the Handler Mappings Feature permission, as these can be set to Read, Script, and Execute, rather than the NTLM permissions on the folder. I would expect that you would need ISAPI-dll Handler mapping to be enabled: 1. In IIS, go to the websites bin dir 2. Open the Handler Mappings Feature 3. Open Actions -> Edit Feature Permissions. 4. Select Read, Script, and Execute – Andy B Sep 30 '17 at 20:21
  • Another thing to check/compare would be the ISAPI and CGI Restrictions, as quite often you need to specify which dlls are allowed to be used or set allow all unspecified modules in the edit feature settings link of the feature (note this is set at server level). You could also compare the ISAPI Filters feature at site level on the 2 servers. – Andy B Sep 30 '17 at 20:21
1

Try using the Global Assembly Cache Tool (gacutil.exe) to publish the missing assembly to the 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

The .NET runtime scans for assemblies in the GAC when it cannot locate an assembly referenced by the project at a local path. We typically use the GAC for assemblies shared by several applications, but we can try this approach for troubleshooting.

If the application in question runs successfully after publishing these assemblies to the GAC, there may be a problem with the assembly reference properties in the project that uses them.

After testing, we can remove the assemblies that we added from the GAC:

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

gacutil.exe comes with the .NET Windows SDK. To avoid installing this on the server, we can use PowerShell to install the assemblies:

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

Both tools require administrator privileges on the server.

Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83
  • Thanks, Cy. I still get the same exception showing up in the Event Log even after installing all 3 ImageMagick DLLs to the GAC. I guess my next step is to use [Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon), as [Michael Liu](/users/1127114/michael-liu) suggested, to work out _which_ dependency is failing. Thanks for your help! – Owen Blacker Oct 02 '17 at 08:35
  • (It's the VC++ runtime, which is definitely installed. More details on the comment thread to the question, in reply to Michael.) – Owen Blacker Oct 02 '17 at 11:56
  • @OwenBlacker Sounds like progress! I took a look at the pastebin. Do you know which version of the vcredist package you installed? We're trying to load the x86 DLL for Magick which may require the x86 VC++ runtime (the server may may only have the 64-bit version installed). – Cy Rossignol Oct 02 '17 at 23:29
1

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.

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70