I have a simple “Monogame Windows Project” template. Within the main directory of the project there is a “Content” folder, and inside it there’s a “Content.mgcb” file. Also, in the “Game1.cs” file in the constructor, the root directory of the content manager is set to “Content”.
Now, if I add an image into the Content folder, and set the “Copy to Output Directory” property to “Copy if newer” and the “Build Action” property to “Content”, then (assuming the name of the image is “image.png”), the following line of code inside “LoadContent” works properly:
Texture2D image = Content.Load<Texture2D>("image.png");
Great! Images work perfectly; no issues there.
As soon as I do the same thing with a spritefont, it throws an error. Specifically, I did the exact same process as above only with a file called “font.spritefont”. Then in the “LoadContent” method, I added the following line:
SpriteFont font = Content.Load<SpriteFont>("font.spritefont");
(Note: I know that you don’t have to add the file extension to the name of the file you’re trying to load, I’m just doing it to make it more explicitly clear that the file I’m trying to load is a valid type, and from my tests I’ve noticed no differences no matter if the extension is included or not.)
The above line of code gives me the error “Could not load “font.spritefont” as a non-content file.”
Very strange, I thought this would work. Then, upon doing further research, I found that the Monogame Content Pipeline only excepts .xnb files.
Alright, so I supposed I was just being stupid and all along all the tutorials were actually telling me I had to use a .xnb file. So, I used the Content Pipeline to try to build my spritefont into a .xnb file. I double clicked “Content.mgcb” in my Content folder, then I added “font.spritefont”, and then I pressed “Build”.
Hilarity then ensued, as the program gave me this error:
Build started 04/05/2015 8:45:26 PM
Building Font C:\Windows\Fonts\SegoeUIMono-Regular.TTF
System.DllNotFoundException: Unable to load DLL ‘freetype6.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at SharpFont.FT.FT_Init_FreeType(IntPtr& alibrary)
at Microsoft.Xna.Framework.Content.Pipeline.Graphics.SharpFontImporter.Import(FontDescription options, String fontName)
at Microsoft.Xna.Framework.Content.Pipeline.Processors.FontDescriptionProcessor.ImportFont(FontDescription options, Single& lineSpacing, Int32& yOffsetMin, ContentProcessorContext context, String fontName)
at Microsoft.Xna.Framework.Content.Pipeline.Processors.FontDescriptionProcessor.Process(FontDescription input, ContentProcessorContext context)
According to this error I’m missing some dll called “freetype6.dll”. I did some google searching and only turned up one useful page, which told me I was missing “zlib1.dll”. I couldn’t figure out how to install it, so I just decided to move on.
My next mission was to figure out how to load SoundEffects, but before we get into that, something really strange happened. The line of code calling
Content.Load<SpriteFont>("font.spritefont") was now throwing a different error than before: The method or operation is not implemented.
… What? Now the method for loading SpriteFonts simply isn’t implemented? That’s crazy, what on earth happened? I didn’t change anything so far as I can tell, I did press “Clean” in the Monogame Content Pipeline but I don’t think that would have any effect on this though, would it?
Even stranger is that now when I create a completely empty “Monogame Windows Game” solution template, and try to do the same things as above, I get the same error, telling me the method or operation is not implemented. What is happening now?
Whatever, maybe if we try to figure out how to load sound effects, we’ll learn something about the Content Pipeline that will help us with the above problem. So I tried doing the same process as with the original image, only this time with a file called “sound.wav”. Then I added the following line of code to “LoadContent”:
SoundEffect sound = Content.Load<SoundEffect>("sound.wav");
This time it gave a slightly different error. It didn’t say “could not load “sound.wav” as a non-asset file.”, it just says “could not load asset “sound.wav”.” Okay, what if we changed it to “Audio” instead?
Audio sound = Content.Load<Audio>("sound.wav");
That gives the same error.
After that, I don’t know what happened, but it started telling me
Content.Load<SoundEffect> was not implemented! I have no clue what I changed, probably nothing, and it just started giving me this error!
Even weirder is that I can’t find any information on the internet about other people having this problem where the ContentManager just sporadically stops working like this. I don’t even know what I could change that could cause an error like this, let alone what was actually causing it.
Now I’m completely stuck. Any ideas?