RIA Services – Finding the InnerException
Thursday, September 10, 2009 at 09:44AM One of the challenges I’ve run into with using RIA services is that sometimes you get back a message saying check InnerException only to find it is null.
In the following example, I had deleted some data and submitted changes. I set a break point on the server side in the delete method so I knew that it’s getting called and ran ok. Back on the client side I would see an exception when checking the results of the submit operation as you can see in the following example. The catch is notice that the message tells me to check the InnerException which is null!
While I clearly believe this is a bug and have reported it, I wanted to share how I track down what the real error is. The quickest path I have found is to override the PersistChangeSet method on the server DomainService. As you can see in the following example all I do is capture the error and I can set a break point. You can now quickly determine what the error is. If you want, this is also where you could “fixup” the exception to pass back a more meaningful message.
Update: From Nikhil - He suggests overriding Submit which is a good sugestion, the idea is you need to catch the error server side in order to know the "why" so there's two places you can hook into if you want.
David Yack |
4 Comments |
Reader Comments (4)
I'd recommend overriding Submit rather than PersistChangeSet.
This one is relatively minor, but I'd suggest using throw; rather than throw ex; so the stack trace on the exception stays intact.
Thanks Nikhil - I added a note to the post in case people don't read down thru the comments.
Keep in mind that the current error handling for non-verification based exceptions is in the DataServiceFactory AKA DataService.axd which is the piece that is being chucked in the next version of RIA Services in favor of ADO.NET Data Services. I suppose that means that Nikhil gets to "fix" this bug using his delete key.
David,Excelent article.
You have to mention that <customErrors mode="Off"/> needs to be in the Web.Config file in the <System.Web> section otherwise You won't get the innerexception. I had a hard time trying to get the inner exception until I realized this.