This project has moved. For the latest updates, please go here.

Web Application Difficulties

May 30, 2013 at 3:53 PM
I am having some difficulty using the MagickNet library in a web application. I am using the x86 libraries on my development PC. I am publishing the code to an IIS Application pool with "Enable 32-bit Applications" set to True.

The application works well in Visual Studio Web 2012 Express, but the deployed application results in:
Could not load file or assembly 'Magick.NET.DLL' or one of its dependencies. The specified module could not be found.
I will work on getting x86_64 (my end goal) working once I get this going.
May 30, 2013 at 6:03 PM
Edited May 30, 2013 at 6:25 PM
I realized that the ImageMagick folder wasn't getting deployed. I added this reference to the project, but now it throws a System.BadImageFormatException.

I copied the 64-bit DLLs to my bin folder. I published the code to the server and changed the "Enable 32-bit Applications" to False. I stopped/started the pool and now I get the BadImageFormatException.

This happens in both the development and production environments (both Windows 7, x86_64)

Any help would be much appreciated!
Coordinator
May 31, 2013 at 4:32 AM
You are getting the BadImageFormatException because you are trying to load a x86 dll in a x64 application pool. Did you also replace the files in the ImageMagick directory? It seems that there is still a x86 dll in your bin directory.
Jun 4, 2013 at 4:15 PM
Thanks for your reply dlemstra.

I have tried many things to get the deployed web application working. I have disabled 32-bit mode web applications and replaced the DLLs with the x64 DLLs directly from the zip file (I downloaded the latest versions of Q8 today). I still get the BadImageFormatException when running the application on the server.

I tried poking around in ildasm at the manifest and everything checks out as far as ILONLY vs 32BITREQUIRED. Is there any way to verify the target architecture of the native DLLs?

Can you offer any additional advice?
Coordinator
Jun 4, 2013 at 4:59 PM
What is the complete name of the zipfile you downloaded?
Jun 4, 2013 at 5:40 PM
I downloaded Magick.NET-6.8.5.402-Q8-x64-net40-client.zip and Magick.NET.Web-6.8.5.402-x64-net40.zip.

I am more comfortable with Mono+Apache.. so this might sound like an odd question. Is there any chance that IIS has cached some of the DLLs?
Coordinator
Jun 4, 2013 at 6:24 PM
I used dumpbin to verify that all the dll's in the zip files you downloaded are x64. Did you install the x64 version of Visual C++ Redistributable for Visual Studio 2012? Which version of IIS are you using? And would you mind posting a more detail exception message that includes a stacktrace?
Jun 4, 2013 at 7:03 PM
I have the x64 version of the Visual C++ Redistributable installed. I am using IIS 7.5 on Windows 7 x64.

Here is the load trace:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\SYSTEM
LOG: DisplayName = AssetTracker
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: AssetTracker | Domain ID: 3
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/ETAD/General/arossign/release/AssetTracker/
LOG: Initial PrivatePath = C:\ETAD\General\arossign\release\AssetTracker\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\ETAD\General\arossign\release\AssetTracker\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/7772d491/8555bc9/AssetTracker.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/7772d491/8555bc9/AssetTracker/AssetTracker.DLL.
LOG: Attempting download of new URL file:///C:/ETAD/General/arossign/release/AssetTracker/bin/AssetTracker.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Here is the stack trace:
[BadImageFormatException: Could not load file or assembly 'AssetTracker' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   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) +210
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122

[ConfigurationErrorsException: Could not load file or assembly 'AssetTracker' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12761078
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): Could not load file or assembly 'AssetTracker' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
Just to be sure, I re-copied the DLLs directly from the zip files.
Coordinator
Jun 4, 2013 at 7:26 PM
Does your AssetTracker dll target AnyCPU or x64? Maybe you have to empty the directory 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files'? You could also use the program Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) to see what the application is trying to load.
Jun 4, 2013 at 7:33 PM
My application targets AnyCPU, but I changed it to target x64 (which makes sense) and it still does not work.

I purged that directory and ran into the same problem.

I'll try out process monitor to see if I can debug this issue further.
Jun 4, 2013 at 10:02 PM
Edited Jun 4, 2013 at 10:04 PM
Resolved!

I managed to resolve the issue. I put ildasm onto AssetTracker.dll and noticed 32BITREQUIRED in the manifest. I am using Visual Studio 2012 Web Express and I thought I was targeting x64, but apparently this was not the case.

I looked into the csproj file and noticed AnyCPU all over the place, despite my x64 settings. I modified the csproj file to target AMD64 and everything seems to be working well.

Thanks for your help, your AnyCPU comment drove me down the path to resolving this issue.
Jul 23, 2013 at 11:33 AM
Hi Team

I am also facing the same problem of "Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found".

My system is of 32 bits. I have downloaded the dlls "Magick.NET-6.8.6.601-Q8-x86-net40-client" and "Magick.NET-6.8.6.601-Q16-x86-net40-client" and added as a reference in my project but same error. I have gone through some of the solutions but not being able to still. I have added the dll in bin/release as well but not able to figure out the problem as this what we normally do we download and added the dll's as a reference in our project and use the methods.

I am using vs2010.

Kindly help. Would you mind providing a sample app in which this dll is being used to resize the animated gif image file.

Thanks in advance
Coordinator
Jul 23, 2013 at 11:41 AM
Did you install Visual C++ Redistributable for Visual Studio as described here: https://magick.codeplex.com/documentation? I will start working on the sample package for Magick.NET this weekend. I will include resizing an animated gif as one of the examples.
Jul 24, 2013 at 4:47 AM
Edited Jul 24, 2013 at 4:57 AM
Hi dlemstra hope you are doing good!
Thanks for your quick asssistance toward my issue. I have installed the vs c++ pack and its working.

A small concern I am using below code to resize .gif file without losing its animation part.
byte[] getResizedImage(String path, int width, int height)
        {
            WebClient wc = new WebClient();
            System.IO.Stream stream = wc.OpenRead(path);
            System.Drawing.Bitmap imgIn = new System.Drawing.Bitmap(stream);
            Image thumb = imgIn.GetThumbnailImage(200, 90, () => false, IntPtr.Zero);
            System.IO.MemoryStream outStream = new System.IO.MemoryStream();

            using (MagickImageCollection input = new MagickImageCollection(stream))/__/Here when i pass stream object it gives error "Magick: zero-length blob not permitted `' @ error/blob.c/BlobToImage/345"__

using (MagickImageCollection input = new MagickImageCollection(path))//__but when i pass the direct path then it works properly__ . Would you mind explain me about it. If i want to pass the stream how can i do that.
            {
                using (MagickImageCollection output = new MagickImageCollection())
                {
                    for (int i = 0; i < input.Count; i++)
                    {
                        MagickImage image = input[i];
                        image.Resize(200,90);
                        output.Add(image);
                    }

                    output.Write(outStream);
                }
            }
 return outStream.ToArray();
}
And one more concern how to verify that if Visual C++ Redistributable for Visual Studio already installed on the system. Also after installing the same will it effect on the any other application developed in vs or any thing else. Why I am asking this because I have to install the same on the client server machine and there are many other major applications are running so I am concerned about it. I have a demo with client for this issue in IST 5pm so I have to make it working live on the from the client machine.

Thanks alot.
Coordinator
Jul 24, 2013 at 4:55 AM
You are receiving that error message because you are trying to read from the same stream twice.
  // First time
  System.Drawing.Bitmap imgIn = new System.Drawing.Bitmap(stream); 

  //Second time (Position is at end of file an will result in an error)
  using (MagickImageCollection input = new MagickImageCollection(stream)) 
Feel free to start a new topic when you have an other issue.
Jul 24, 2013 at 6:27 AM
Thanks dlemstra.

I had one more concern that I has asked before
"And one more concern how to verify that if Visual C++ Redistributable for Visual Studio already installed on the system. Also after installing the same will it effect on the any other application developed in vs or any thing else. Why I am asking this because I have to install the same on the client server machine and there are many other major applications are running so I am concerned about it. I have a demo with client for this issue in IST 5pm so I have to make it working live on the from the client machine."

Would you mind telling me if there is any thing implementing the same on Client Server.
Coordinator
Jul 24, 2013 at 6:51 AM
You can check if the Visual Studio C++ Redistributable for Visual Studio 2008 or 2012 is already installed from the Installed Programs under the control panel. I don't know if installing this can result in problems with other applications because I don't know these applications. I never had problems after installing it but I cannot guarantee that it will be the same for you. You might be lucky and already have the Visual Studio C++ Redistributable for Visual Studio 2008 on your system. That will work together with the .NET 2.0 version of Magick.NET.
Jul 24, 2013 at 7:02 AM
Edited Jul 24, 2013 at 7:04 AM
Hi dlemstra

Thanks for quick assistance really appreciated.

I have one more query can I have the thumbnails of the .gif images without losing its animation please. Because some of the image may be big in size and while I am resizing them with my code not in the size I want. (aspect ratio).

Here I am sending you the real images I want to have the thumbnail of these images without losing animation if any one have .

http://speedy.sh/q3RG2/ActualImage.gif
http://speedy.sh/FDSRe/ActualIMageOutputafterResize.JPG
http://speedy.sh/pvCSX/I-want-the-same-size-of-all-images-after-resize-or-lil-more-but-not-more-than-this.JPG.

Thanks in advance.
Coordinator
Jul 24, 2013 at 7:38 AM
Your link wants me install an executable and I don't really feel like doing that. You can contact me trough codeplex if you need more help.
Jul 24, 2013 at 7:43 AM
Thanks
Do let me know how can i contact you on codeplex as I dint find way to. .
Also , Can I have the thumbnails of the .gif images without losing its animation please please.
Coordinator
Jul 24, 2013 at 7:49 AM
There is a contact button on my profile page.
Sep 11, 2013 at 5:00 AM
Edited Sep 11, 2013 at 2:10 PM
Hi dlemstra

I am able to resizing the images or gifs files. But there here I have come across new problems of images getting squashed while resizing them. for eg an image of size 856750 when resized using the dll it is squashed I am resizing to (22090). I need the image quality should not lose and it should not squashed. Please help.

Also the problem I am facing with the height. I want to calculated the height according to width but it should be in aspect ratio means It should maintain the aspect ratio. How can I do that ?

Thanks in advance.
Coordinator
Sep 11, 2013 at 6:46 PM
Could you start a new topic instead of using an old one? And can you add a short code example with a link to an input and output image?
Sep 25, 2013 at 5:22 AM
Edited Sep 25, 2013 at 5:25 AM
Hi

I'm getting also this issue on deployment to production:

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.
Also framework use is 4.0

Visual Studio C++ Redistributable for Visual Studio for 2010 is installed on localhost.. Thus it need to install on prod server?

Hope to hear from you soon thanks..

Benjo
Coordinator
Sep 25, 2013 at 8:24 AM
You need to install Visual Studio C++ Redistributable for Visual Studio for 2012 on your production server. A link to a download can be found here: https://magick.codeplex.com/documentation
Oct 24, 2013 at 5:07 PM
Edited Oct 24, 2013 at 5:07 PM
Hi,

I am having the same problem, have tried all the suggested steps in this thread and still no luck.

-I created a sample project (MVC 4) in VS2012 and use NuGet to install the Magick.net (PM>Install-Package Magick.NET-Q16-x64)
-installed the VS c++ Redist for VS2012 (link from the documentation)
-changed the project build to target x64.

I still get this error

Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Do I need to install the ImageMagick application from ImageMagick.org to my local machine?

Thanks
Coordinator
Oct 24, 2013 at 8:44 PM
You don't need to install ImageMagick itself. Did you set your application pool to 64 bit?
Oct 25, 2013 at 7:29 AM
I don't have a solution to your problem jcvu01 but fro my experience the x86 worked better for me and I didn't have to set my project to x64 although I am receiving this warning
"Warning 1 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\PathToBin\Binary.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project."
Everthing works well.
Installing the package by NuGet should be enough!