This project has moved and is read-only. For the latest updates, please go here.

Unhandled exception System.BagImageFormatException

Mar 5, 2015 at 11:13 PM
Edited Mar 5, 2015 at 11:15 PM
Been banging my head on this all afternoon. I was successfully able to get the 64bit version up and running in an Windows Form earlier in the day. Now I've started a new project, added the x64 DLL as a resource. And it errors every time.
"An unhandled exception of type 'System.BagImageFormatException' occurred in System.dll"
"Additional Information: Could not load file or assembly 'Magick.NET-x64..."

The only thing that's different is now I'm using a FileSystemWatcher. So is it because of the threading that cannot load?

I've tried setting the build of the program to x64 and x86 and tried both DLLs.
private void eventRaised(object sender, System.IO.FileSystemEventArgs e)
            switch (e.ChangeType)
                case WatcherChangeTypes.Created:
                 //   createComposite(e.FullPath);
                    string newFile = e.FullPath;
                    using (MagickImageCollection images = new MagickImageCollection())
                        //add the 1st image
                        MagickImage image = new MagickImage(newFile);

                        string appPath = Path.GetDirectoryName(Application.ExecutablePath);

                        //add the background
                        MagickImage background = new MagickImage(Path.Combine(appPath, "ripkenbg.jpg"));

                        //do the composite and write over the image
                        image.Composite(image, Gravity.Center);
                        image.Write(string.Format(@"c:\workspace\HFPoutput\{0}", Path.GetFileName(newFile)));
                    StatusUpdate(string.Format("File {0} has been created\r\n", e.FullPath));

                default: // Another action
Mar 6, 2015 at 5:55 AM
You will get a BadImageFormatException when you try to load a 32 bit assembly in a 64 bit worker process or the other way around.
Mar 6, 2015 at 8:38 PM
sorry I didn't see the check mark that it would "prefer 32". Thanks!