Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I'm very new to coding so try to bear with me a bit. I'm trying to embed a Monogame control inside a Windows Forms Application. I've been using code from this Microsoft sample Xbox LIVE Indie Games - winforms series 1: graphics device[^] as suggested by this CodeProject answer: How to render with XNA 4.0 inside a Windows Form?[^]

After adding Maxim's code to a new class, adding the necessary references, inheriting GraphicsDeviceControl in a new class, squashing 2 build errors, building the solution, adding the new control from the toolbox and debugging, I've gotten a fatalexecutionengineerror at this line in the GraphicsDeviceService class.
C#
graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters);

It says "Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:...\bin\Debug\MyOwnAdvice.vshost.exe'." Here is the exception detail for the error:
FatalExecutionEngineError occurred
HResult=-2146233082
Message=Exception of type 'System.ExecutionEngineException' was thrown.
InnerException:
I'd like to figure out where this error is coming from and how I can get around it. I thought at first it was because I was using code meant for XNA instead of monogame, so I used this tutorial Bringing your XNA WinForms Controls to MonoGame + OpenGL | Justin Aquadro[^] to modify the code and implement OpenTK, but this gave a similar error.

If you'd like to replicate this error
1.Create a new Windows Forms Application Project
2.Create a new .cs, paste in Maxim Kartavenkov's code from the earlier codeproject link, and change its namespace to your own. (This code comes from the XBox Live Sample.)
3.Add the Monogame framework reference to your project.
4.Create a new .cs which inherits from the GraphicsDeviceControl class, and give it protected overrides for Initialize() and Draw().
5.Delete the two lines that give build errors, Present and Reset (Maybe this is where I'm going wrong? This is what jaquadro's tutorial focused on removing, and that gave me the same problem.)
6.Build your solution, drag the new control from your toolbox into your form and debug.
I'm probably missing something really stupid here, but I've been trying to solve this for a week now and my Google-Fu is coming up short. Thanks for reading!
Posted
Updated 23-Dec-15 7:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900