Monday 25 October 2010
A common XNA error
One of the XNA errors that regularly manages to confuse me is the exception:
Service provider object of type <Insert your object here> must be assignable to service type System.RuntimeType.
Since a quick Google search for the exception provided few results I figured I post the cause and solution.
In XNA there is the game.ServiceProvider object that provides a neat service based way of storing you game services without tying them directly to business logic. The predominant way of calling this method is:
this.Services.AddService(typeof(<Iinterface>), <Object>);
The exception occurs when your <Object> does not implement the provided <Iinterface> interface. Really simple and trivial to fix. Unfortunately forgetting to implement a particular interface seems to be something I regularly when I am developing a piece of functionality in small chunks of time. Just unfortunate that the error message is so unspecific.
Hope this helps
-Leon
Subscribe to:
Post Comments (Atom)
Thanks this helped me out.
ReplyDeleteThis helped me out as well, thank you for being straight-to-the-point.
ReplyDelete