[SOLVED] SpriteBatch System.AggregateException

The game starts and runs without any problem when I built it without the .net native toolchain.
But if I enable this feature (which MS forces me to do) I receive following exception:

Exception thrown: 'System.AggregateException' in System.Private.Threading.dll
Additional information: AggregateException_ctor_DefaultMessage
If there is a handler for this exception, the program may be safely continued.

And this occurs at SpriteBatch = new SpriteBatch()

protected override void Initialize()
    SpriteBatch = new SpriteBatch(Graphics.GraphicsDevice); // <--- HERE
    Graphics.IsFullScreen = true;

Did someone else experience that problem?

EDIT: If I put the SpriteBatch = new … into the “LoadContent” method, same negative result.

I used to get those all the time when developing for Win8.1 Store. You can ignore them and continue.

NETFX use exceptions extensively for flow control. SpriteBatch doesn’t use anything related to threads. That’s just an exception thrown internally from the system and then re-thrown as AggregateException from the game-loop thread. It’s annoying but nothing to worry about. You can uncheck the ‘Break when this exception type is thrown’ to avoid seeing this all the time.


Or perhaps catch the error and throw it at the debug window/console? :hushed:

Better to log than create a habit of ignoring every error…

Just a random thought…


Yes, but that exception gets thrown everytime. Catching does not work somehow. It does not enter the catch clause, even if the exception scope is set to “Exception”.

But anyway, it works even with that exception. Just wanted to share here my findings

Logging does not qualify as ‘handling’ an error. I strongly oppose this practice. You must catch exceptions only when you know how to recover from that specific error. Otherwise you should left it unhandled and let the program abort.

Of course it doesn’t, because the source of the exception is coming from another thread, from an async function inside the OS. Be sure that the OS already handled this error and as the message says ‘the program may be safely continue’. if it doesn’t you are not in position to handle & recover from it anyway, in that case the program will just fail and terminate.

VS2012 used to pause on those errors all the time when developing for Win8.0. Nowdays VS2015 is better at ignoring those unrelated exceptions but I suppose they still pass through when you switch to Net.Native.

EDIT: …or maybe you will still get those when you enable ‘managed & native debugging’. I don’t know.

I was more referring to coming back to it later if it was minor at this point in order to patch it before release…

I did not think if it was a multi-thread scenario, good call! [Referring to further in your reply]