FreeImageAPI throws MissingMethodException

One of our three team members is getting strange errors during Content building, specifically with texture importing. The other two of us are able to build the same content just fine. If it helps, he is using Windows 7 and VS2012 Express.

The error is occurring on around 1/8 of the textures being imported. I’m not familiar with png encoding, so it’s just a guess, but I was wondering if different encoding/formats would explain why some fail and not others. I plan to explore this as a possible workaround in case it just requires saving the images in a different format. However, I’m still really curious as to why it would fail on his computer and not ours, and whether any of you have seen this before.

Below is a sample of one of the errors from the stack trace, and the .png in question is below that… I’ve also included an example of a .png that is importing successfully. Thanks in advance for any help!

    C:/DEV/gbjam3/Bazaar/Content/textures/game/menu/titlescreen.png: error: Importer 'TextureImporter' had unexpected failure!
System.TypeInitializationException: The type initializer for 'FreeImageAPI.MemoryArray`1' threw an exception. ---> System.MissingMethodException: Method not found: 'IntPtr System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(!!0[], Int32)'.
  at FreeImageAPI.MemoryArray`1..cctor()
  --- End of inner exception stack trace ---
  at FreeImageAPI.MemoryArray`1..ctor(IntPtr baseAddress, Int32 length)
  at FreeImageAPI.Palette..ctor(FIBITMAP dib)
  at FreeImageAPI.FreeImage.GetBitmap(FIBITMAP dib, Boolean copyMetadata)
  at Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.Import(String filename, ContentImporterContext context)
  at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
  at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent)


A .png that is working fine:

EDIT: Removed a red herring :smile:

Well, that’s one mystery solved… the “stick.png” reference at the end of the stack trace is actually just a separate line of regular output from the build process. It had nothing to do with the stack trace; it just appeared on the same line because there was no newline character. So there is an issue with titlescreen.png that is not present in either of the other two attachments.

I was able to resolve the errors through experimenting with png formats.

First I opened some of the images (ones without transparency) in MS Paint and used “save as” to save them as pngs again. For the remaining images, I used paint.NET and saved them with a bit depth of 32 instead of 8. That seemed to fix all of the remaining errors.

So I believe it is safe to conclude that encoding/formatting was the main factor in whether the error was being triggered. We still don’t know why it was only happening on one PC. It may be a one-off problem that nobody else will run into and does not need to be investigated further.

Still, if anyone else runs into this, hopefully the above steps will help :smile: