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

Initializing error

May 27, 2014 at 12:39 AM
Edited May 27, 2014 at 12:40 AM
Hello,

I am doing some test with ImageMagick dll.

I get initialization error with the
An unhandled exception of type 'System.TypeInitializationException' occurred in Magick.NET-AnyCPU.dll

The dll is correctly referenced. The OS is win7 64bit with VS 2010. The dll version is 6.8.9.002,

The code is listed below:
    private void button1_Click(object sender, EventArgs e)
    {
        using (MagickImageCollection images = new MagickImageCollection())
        {
            MagickImage first = new MagickImage(@"D:\temp\temp1\image1.jpg");
            images.Add(first);

            MagickImage second = new MagickImage(@"D:\temp\temp1\image2.jpg");
            images.Add(second);

            using (MagickImage result = images.Mosaic())
            {
                result.Write(@"D:\temp\temp1\image10.jpg");
            }
        }
    }
Could someone tell if other settings are necessary? Thanks!

Steven
Coordinator
May 27, 2014 at 7:09 AM
Can you try if setting MagickAnyCPU.CacheDirectory to a directory that your process can write to and see if that resolves your problem? If that does not resolve your problem can you post a more detailed stack trace?
May 27, 2014 at 7:58 AM
Hi

Thanks for the quick replay.

It doesn't help with setting MagickAnyCPU.CacheDirectory = ...

Here is the stack output on the break point:

The thread 'vshost.LoadReference' (0x2038) has exited with code 0 (0x0).
'LearningIMMa.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Mydoc\entw\learning\csharp\LearningIMMa\LearningIMMa\bin\Debug\LearningIMMa.exe', Symbols loaded.
'LearningIMMa.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Mydoc\entw\learning\csharp\LearningIMMa\LearningIMMa\bin\Debug\Magick.NET-AnyCPU.dll'
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
'LearningIMMa.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_zh-Hans_b77a5c561934e089\mscorlib.resources.dll'
A first chance exception of type 'System.TypeInitializationException' occurred in Magick.NET-AnyCPU.dll
A first chance exception of type 'System.TypeInitializationException' occurred in Magick.NET-AnyCPU.dll
An unhandled exception of type 'System.TypeInitializationException' occurred in Magick.NET-AnyCPU.dll

Additional information: “ImageMagick.Types” initial setting caused exception。

BTW I am running on a Chinese Version of Win7 64.

Steven
Coordinator
May 27, 2014 at 8:07 AM
Did you install the Visual C++ Redistributable?
May 27, 2014 at 8:15 AM
Yes, 2008, 2010 and 2012 are installed.
Coordinator
May 27, 2014 at 8:20 AM
Can you attached a debugger and post all InnerExceptions of the TypeInitializationException that has been raised?
May 27, 2014 at 8:48 AM
A first chance exception of type 'System.TypeInitializationException' occurred in Magick.NET-AnyCPU.dll
System.TypeInitializationException: “ImageMagick.Types” initial setting caused exception. ---> System.TypeInitializationException: “ImageMagick.AssemblyHelper”initial setting caused exception. ---> System.IO.FileNotFoundException: can't load “Magick.NET-Q16-x86.dll”or one of its dependency. Can't find the module.
在 System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
在 System.Reflection.Assembly.LoadFile(String path)
在 ImageMagick.AssemblyHelper.LoadAssembly()
在 ImageMagick.AssemblyHelper..cctor()

....

So The MagicAnyCPU doesn't include all lib, I still need to download and reference to "Magick.NET-Q16-x86.dll" ?

Steven
Coordinator
May 27, 2014 at 9:17 AM
The Magick.NET-AnyCPU version has the x86 and x64 version of the Magick.NET library embedded. When the AnyCPU library is loaded it will either load the x86 or the x64 version. The message cannot find the module looks like the Visual C++ Redistributable was not installed. Did you install both th x86 and the x64 version? It looks like your application targets x86 instead of AnyCPU.

I will see if I can figure out a way to improve the error message.
May 27, 2014 at 9:45 AM
I tried to change the platform in application property to "x64" and "AnyCPU", they both are working, but not "x86".

It was set to"x86". Maybe there is problem with embedded "x86" version ?

For now Thanks a lot for the tip and answers!

Steven
Coordinator
May 27, 2014 at 10:14 AM
Edited May 27, 2014 at 10:16 AM
I think you did not install the x86 version of the Visual Studio C++ Redistributable. I have no other reports about a corrupted version of the x86 library embedded in the AnyCPU dll.

Good luck with using Magick.NET in your application.
May 27, 2014 at 2:31 PM
Indeed it is because of lacking x86 C++ Redistributable.

Thanks!