Issue
We ran into a rather silly issue with a recent Silverlight deployment. In our RIA services is it not uncommon for use to throw custom exceptions from the RIA side and then have our Silverlight application display them to the user.
For instance we would throw a custom exception if there was an issue with the login and we would expect the following to be "User and password is invalid" to be displayed. However we were getting "Load operation failed for query 'Login'. Exception of type 'System.ServiceModelServices.Client.DomainOperationException' was thrown."
What we noticed is anytime we through a custom exception it was being returned as DomainOperationException instead of the custom exception type. This drove us nuts because it was working in each of our development environments but not on this integration machine we were using for testing. We did some searches on DomainOperationException but really could not find much that helped. We did find this blog (http://weblogs.asp.net/fredriknormen/archive/2009/12/08/wcf-ria-services-exception-handling.aspx) however it was poorly written.
Solution
Well the solution was really simple. All we had to do was make the following modification to our web.config where the RIA Services were hosted.
<customErrors mode="Off"/>
5 comments:
Hi
Thanks for your post.
Is it possible to have customErrors on for the rest of the website yet turn them off for the RIA Domain Service?
I've have tried setting two locations with different settings but to no avail. Thanks.
e.g.
<location path="">
<system.web>
<customErrors mode="On" />
</system.web>
</location>
<location path="ClientBin">
<system.web>
<customErrors mode="Off" />
</system.web>
</location>
Rob,
Thanks for the feedback.
Not totally sure what you are trying to achieve. Are you saying you want to have custom exceptions on the RIA side that do not raise to the Silverlight app? I wrote this - http://www.astaticstate.com/2010/04/ria-service-domain-service-method-life.html
What you can do is catch all errors in the OnError override and then only throw exceptions to the Silverlight application that you want...
Jason
Thanks, I'll have a look at the article.
My Silverlight app is only part of a system which runs as an ASP.NET 3.5 IIS application. For the rest of the website we want custom errors on for security reasons.
For my RIA Services app I would like to be able to pass certain errors back to the Sliverlight client.
e.g. throw new FriendlyException("Error generating report.");
I'm not sure whether RIA Services only looks at the main customErrors tag or whether you can set this for a particular folder. I attempted it on the ClientBin folder because this is the root of the URL that the RIA Services HTTP requests are routed through.
Hope I've explained things better!
Ta
Rob
Rob,
I wish I could say I knew the answer. I have been creating dedicated RIA services for my Silverlight applications.
Did you try to deploy the RIA Services to a different web site and not intermix the two? They may be a good thing to think about anyways so your RIA Services do not compete for the same resources with the ASP.net application.
Jason
Hi
I found a much better way in the end than turning off custom exceptions for the whole site or splitting out the Silverlight onto a different domain.
I found that if you throw a DomainException instead of your custom exception, you can pass back the full details to the Silverlight client.
Rob
Post a Comment