Trouble building importing and processing fnt files

I’m trying to import and process fnt files via mgcb with an imported dll I built (target .NET Framework 4.8) from this repository MonogameDistanceFont/DistanceFont at master · SometimesRain/MonogameDistanceFont · GitHub (it implements an importer and processor for msdf fonts). But when I’m trying to import the fnt file I keep getting this error: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Drawing.Common, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.

I’m very new to .NET and its toolset, so I have no idea why it’s referring to System.Drawing.Common that has a totally different version than the one I built against or where it’s trying to search for it (the error is very, very sparse).

I’ve also tried to start a new project with all the right defaults from the get-go (per chance the configs in the repo were “too old” by now), copying all the code, adding minimal references via nuget, but the result remains the same.
I’ve searched for System.Drawing.Common.dll on my c drive and the explorer found a ton of them, so I’m not keen on removing one by one to find out which might be the one mgcb is trying to use, possibly breaking something else in the process.

At this point I’m running out of ideas on how to tackle this.
Thanks in advance.

You can get it working but there are some things along the way…

So I would make a new solution and copy all classes and the content over. Then you will need to add a reference to the System.Drawing.Common.dll. I found a working one here:


Also add a reference to the MGCB Editor. This is a bit tricky… Select the root inside the tree view control and then at the bottom you can click and add references. You need to add a reference so that the fnt files can be build by the content pipeline.

Then there is a hack which does not seem to work anymore… But you don’t need the hack. Just use input.GetGraphicsDevice();

I think the Fps implementation is wrong but works good enough and shows 59 FPS constantly.

Also it is necessary to allow unsafe code. To do so you will have to set the compiler flag by adding to the*.csproj file inside PropertyGroup this here:


Thank you for your quick reply.

I’ve done all you’ve said already, in essence, so I’ll describe what I did differently, maybe there’s some obvious mistake I keep making.

I’ve copied the code from the repo into a new solution and used nuget to get the right libraries (started from blank, no libs, I don’t trust my own judgment to chose the right dlls at this point). I’ve built the font dll, which must mean the referred libraries had to be at least good enough for the task. Then I’ve added references to the mgcb as you’ve shown, still no problems, the right importer and processor appear in the options for fnt files (or even get selected automatically if I add them after adding the reference to the new dll). Here’s the tricky part: I’ve added the reference to the System.Drawing.Common.dll as you’ve pointed out (at the same folder on my machine too), still I get the error I mentioned in the OP. I’ve referenced the System.Drawing.Common.dll that gets copied next to the bin/Debug/ folder next to the font dll, thinking it has to be the right one, because it’s the one the dll was compiled against, right? Nope, still the same error.

At this point I cannot think of a thing that is wrong with any of the dlls or the build process, but something far more basic I’m missing and messing up. Can there be any clash with some other System.Drawing.Common.dll mgcb finds as preferable? Or something regarding the versions (using the latest monogame and having a myriad of System.Drawing.Common.dll files spread across the same amount of folders on my machine)?

I’m not sure about input.GetGraphicsDevice(); though, but I think that comes into play later when I get to use the imported and processed fonts.


I have two references in the MGCB Editor.

The assembly you mentioned should work too I guess it has the same size like the one from the nuget and is inside the project and I assume you are right and it is build against this dll.

However I just used the one which visual studio showed me if you look here:

H:\Dev\Programmierung\VS 2019\MonoGame\MonoGame.Kickstarter.Private\DistanceFontMG\DistanceFontMG.WindowsDX\bin\Debug\netcoreapp3.1\runtimes\win\lib\netcoreapp3.1

Yes the part with input.GetGraphicsDevice(); will come into play later…

It’s probably not what I wanted to end up with, but I just couldn’t get this working. I’ve even tried to brute-force and find which System.Drawing.Common.dll was causing trouble by searching for it with a python script, but no-joy. I’m still blaming my not knowing enough about .NET environment and how everything ties together, but I have to start somewhere… I’m really sad that this is such an obstacle, because msdf fonts have many advantages and barely any problems (actually none for what I need them for).

Since I still needed scalable fonts, I ended up with using which has excellent documentation (I rate that on my own ability to actually use something, because, as stated before, a lot of times I’m just parroting things) and it does what it advertises. If anyone else starts losing hair on this problem, maybe this repo can help them solve the problem.

P.S. I’ve searched the forum for ‘FontStashSharp’ and I see there was one reply referring to it, but if only I had known it existed.

1 Like

P.P.S. @Kwyrky thank you for your extensive help regardless. Maybe it will come in handy for something else entirely.

1 Like

I added your link to What options are there for fonts? where I asked a very long time ago which options we have for MonoGame

I don’t think there is very much more to do apart from adding usings for the namespaces if there are ambiguous and / or missing in the solution / project(s) code.

Maybe the project you have found is better anyway? I don’t know which technique is state of the art so to say. Maybe somebody else can tell if this is the way to go. But even if not then if this is what works for you then you don’t need something else.

The demo from the MonogameDistanceFont is pretty nice. Interesting topic, I mean font rendering unfortunately I don’t know much about it :slight_smile:

And the part with the GraphicsDevice is just one line where this change is necessary.

Here is a quick recording of the demo project that was provided with it