Error with MonoGame source when drawing, "CallbackOnCollectedDelegate occured"

Hi everyone,
I’m editing my game’s code on a different computer and I’m trying to compile Monogame from Source so that both machines have the same version.
I followed all the steps on monogame.net/documentation/?page=Setting_Up_MonoGame_Source, and replaced the reference to the Monogame framework with the reference to the newly built Monogame.Framework.WindowsGL project.

After replacing the reference, my game throws this error when Spritebatch.End() is called in the main draw function:

“Error was made in Game.vshost.exe”
“A callback was made on a garbage collected delegate”

The error is brought up in Shader.OpenGL.cs at line 56:
GL.CompileShader(_shaderHandle);

Spritebatch.End is called a few times before this specific call that produces the error, my code looks roughly like this:


Set render target to renderTextureA
Draw game stuff in a few different spritebatches
Set render target to null

Set render target to renderTetxureB

Spritebatch.begin(BackToFront, AlphaBlend, PointClamp, Default, null, null, CreateScale(1f));
Draw renderTextureA
Spritebatch.end() <-- error here

Set render target to null

I’m working on a Windows 10 laptop, the game runs fine if it references the stable, released Monogame 3.6 framework, it only throws this error when it references the source.
It also runs fine from source on my Windows 7 Desktop, just not my laptop.

I’d really appreciate any help, it would be great to know why this is happening with the source version.
Thanks very much!

Does this happen in a new project or are you trying to change references in a project that was created from a older version of monogame using the newly built source ?.

It sounds like a delegate hasn’t been unsubscribed. but i would try to find were that error messege is thrown from as a starting point in the monogame code to see specifically what event is being triggered.
“A callback was made on a garbage collected delegate”.

It’s a new project that’s had the code and content copied over from the other project (from the other computer).
The original was also made with the source version of MonoGame, though it’s been a month or two since it was created so if the source has been updated since then it wouldn’t be the same.

Originally I’d tried copying the MonoGame source files from the Desktop over to the laptop and referencing those so that they were the same version, but it created the same error.

When you say where the error is thrown from, do you mean where in the source is halts the program?
The error pops up at line 56 of Shader.OpenGL.cs, would a stack trace be helpful?