FNA-XNA / FNA

FNA - Accuracy-focused XNA4 reimplementation for open platforms
https://fna-xna.github.io/
2.65k stars 272 forks source link

Improve .NET Native AOT failure message when missing types in rd.xml #479

Closed Rosalie241 closed 9 months ago

Rosalie241 commented 9 months ago

I was playing around with AOT in .NET 8 and when missing a type in rd.xml, it'd show the following exception which confused me:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader) + 0x8e5
   at Microsoft.Xna.Framework.Content.ContentReader.InitializeTypeReaders() + 0x4e
   at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() + 0x1f
   at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String, Action`1) + 0x194
   at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) + 0xc6

so to aid developers like myself in the future, I've changed the exception to be the following:

Unhandled Exception: System.InvalidOperationException: Failed to get constructor for ContentTypeReader. If you're using .NET Native AOT, ensure your rd.xml contains the following type: Microsoft.Xna.Framework.Content.StringReader
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader) + 0x8e5
   --- End of inner exception stack trace ---
   at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader) + 0xb7a