Intermittent "The content file was not found" errors

I’ve been developing a simple menu and using a ttf font with SpriteFont. This is with MonoGame 3.7.1708. I’m building it in Visual Studio 2019.

It’ll work for a while then stop. This is on a cheap Chinese Android. I just tried it on another model of Android (BLU) and it came up with the error. I loaded the Content.mgcb into the PipeLine, did a clean followed by a Rebuild then a rebuild in VS 2019 and ran it without debugging. That worked, as did running with debugging.

It seems to work for a while then something upsets it and it takes the clean/rebuild and rebuild to fix it. Any suggestions?

Hey, I’m having the same issue, except in my case it seems completely random when the content is able to load.

Going through the procedure of a clean followed by a Rebuild then a rebuild seems to have no effect.
I’m running my app through an activity in a xamarin forms app, the actual game itself is located in a monogame shared project.
I’ve tried running it as a standalone project for testing purposes and it seems to work in those cases.

Did you ever figure out a fix for this?

UPDATE:
I believe I’ve found a fix for this.
You need to turn “Use Shared Runtime” off in:
Project > Properties > Android Options

Thanks. It certainly copies a lot more files when you untick that!.60 MB!

Hey, I’m having the same issue. I have not encountered it on previous projects, I have no idea why it happens now. Disabling shared runtime do seem to fix it, but as @DavidBolton mention building takes more time without it, so if anyone find another fix it would save me a lot of time.

I’ve found it can occur for a few reasons:

  1. Something changed in the Project and requires a complete PipeLine Rebuild and Clean… .
  2. Typo, I instead of i in a name.

I’ve also found that quite often a code change won’t trigger a deploy. It runs the previous code.

I’ve taken to doing quite a few changes in one go then doing a clean before a debug run to force a deploy.

Now for me it won’t even work when I disable shared runtime and even after a clean and rebuild. It’s just so random and frustrating… I agree that it seems to occur after some changes were made in the project.

When I run into this type of thing, I go on a /bin and /obj deleting spree. The tooling should regenerate both when you clean and rebuild, but I’ve found that at times it does not, and doing this works. Additionally be sure to delete these directories underneath the Content folders too.

Thanks, this works for me better than the clean and rebuild method which is inconsistent on my end too. But it’s still a temporary fix that allows to build only one time, the error will show up at the next build attempt.

Maybe it happens because the project contains several ddl files. That’s what different for me from other android MG projects.

To automatically “Clean” when clicking the build button you can add these lines to the prebuild event (Settings > Build Events):

del /F /Q $(ProjectDir)\bin
del /F /Q $(ProjectDir)\obj
del /F /Q $(ProjectDir)\Content\bin
del /F /Q $(ProjectDir)\Content\obj

It should save you two click when building if like me this issue is permanent.

1 Like

It’s been more than two months now and the issue keep showing up randomly. I’ve yet to find a reliable workaround, as even the prebuild events above don’t always work, as well as deleting the obj and bin folders. This is driving me insane.

EDIT two weeks later
So for anyone running into this issue, I’m afraid to report that I still haven’t find a proper fix ; I would still get a Content file was not found for no reason, that would or wouldn’t stay after a full clean + rebuild. But I did find something that can help continue to work and test without waiting too much.

I took the time to set up a monogame shared project, that allowed me to run the same code and use the same assets wheter I’m compiling on android or windows. I’m basically only testing the game on windows now, and only when I have to publish/do a specific test on android do I fight with visual studio/monogame and this cursed bug. I had to try several tutorials to set up the shared project. Here’s one that worked for me: https://manbeardgames.com/tutorials/multiplatform-game-development-with-monogame/#method-3-the-monogame-shared-project-approach
I follow the second method proposed by the article and it worked.
Making my android game playable on windows required a few tricks, like emulating a touch collection with a mouse position and state. Here’s roughly how I did it (ms_tc is my emulated touch collection, ms my MouseState):

if (ms.LeftButton == ButtonState.Pressed && previous_ms.LeftButton == ButtonState.Released)
{
    ms_tc = new TouchCollection(new[] { new TouchLocation(0, TouchLocationState.Pressed, Mouse.GetState().Position.ToVector2()) });
}
else if (ms.LeftButton == ButtonState.Released && previous_ms.LeftButton == ButtonState.Pressed)
{
    ms_tc = new TouchCollection(new[] { new TouchLocation(0, TouchLocationState.Released, Mouse.GetState().Position.ToVector2()) });
}
else ms_tc = new TouchCollection(new[] { new TouchLocation(0, TouchLocationState.Moved, Mouse.GetState().Position.ToVector2()) });

I also binded several actions to key press.

I know this is more of a way to escape the problem rather than to solve it, but that’s what allow me to continue the developpement. The additionnal bonus is that you now have a port of your android game on desktop.