[SOLVED] InvalidOperationException in Texture2D.FromStream()

Hello there!

I’m trying to make a map editor using winforms & monogame.
When using

Texture2D.FromStream(monogameControl.GraphicsDevice, File.Open(fileName, FileMode.Open));
//monogameControl: see http://pastebin.com/q2Ewdtmy

I get a System.InvalidOperationException with message “This image format is not supported”. (Though the image is a *.png (I also tested *.jpg; same error))

Innerexception: {“Can’t load DLL api-ms-win-core-com-l1-1-0.dll: Can’t find module. (Exception of HRESULT: 0x8007007E)”}
(Roughly translated)

The monogameControl class I’m using: http://pastebin.com/q2Ewdtmy
I already tried installing Visual C++ Redistributable for Visual Studio 2015, but no luck.

Does anyone know what’s causing the problem?

Does it happen even with a simple bmp?

Yep, it does


Are you building for x64?

I’m building x86

I just tried x64, any cpu; same error

The MGControl class doesn’t help us much, I think. What are the details of the PNG? Bit depth, etc?

What MonoGame platform are you using? That it can’t load a core Windows library such as api-ms-win-core-com-I1-1-0.dll is odd. Those api-ms DLLs were introduced in Windows 7.

From this MSDN page, it would appear that api-ms-win-core-com-I1-1-0.dll is not available in Windows 10 UWP apps. Are you building a desktop app or a UWP app?

It’s just a desktop app (WindowsFormsApplication).
It’s literally every image.
The image I tested it with was a 32x32 with bit depth 24.
I’m running windows 7.

I just tried making a workaround. I tried copying the image file to the content directory and loading it using a contentmanager. It gave me another exception “This image format is not supported” but still with the same Innerexception: {“Can’t load DLL api-ms-win-core-com-l1-1-0.dll: Can’t find module. (Exception of HRESULT: 0x8007007E)”}


Well uhhh… This is embarrassing…
By asking wich MonoGame platform I’m using I realised my mistake.
I just remade the project using the right platform. Problem fixed.

God I’m stupid. :sweat:
Sorry for wasting your time!

Thanks for all the help!

Walk of shame

Hi @Duts1337,

I seem to run into a very similar problem:

My Monogame application (x86, DektopGL, compiling for windows) is compiling fine on my Laptop (Core i7 x64 bit system). Trying to do the same on my desktop (Core i3 x64 bit system) gives me the error: System.InvalidOperationException: "This image format is not supported" when trying to read in a png file via Texture2D.From Stream().

I am already using x86 as the target platform - what levers did you set when switching the Monogame platform?


Sounds like a diffrent problem :frowning:
I had the error when I updated monogame to 3.6.
I removed the references to Monogame.Framwork.dll in my existing project and added the newer version. Turns out I added the wrong version of Monogame.Framwork.dll to my project’s references.
IIRC I just created a new monogame desktop project and added all my old classes and stuff (It was a pretty small project anyway).

Hope this helps!

Hi Duts,

Thanks for your fast reply. I will try the same and see if it works.