8

I have the following code on the server:

if (actualRowCount > maxRows)
{
    throw new DomainException("OverMaxRowLimitException",
        new OverMaxRowLimitException(string.Format(MaxRowsMessage,
        actualRowCount, maxRows)));
}

This creates a new DomainException with the InnerException property set. I've verified that this is set in the debugger.

The custom exception is defined thus:

public class OverMaxRowLimitException : Exception
{
    public OverMaxRowLimitException(string message)
    {
        this.Message = message;
    }

    public new string Message { get; set; }
}

This is supposed to return a sensible error message to the client so the user can be told there are too many rows. So in the load complete handler we'd like to have:

if (result.HasError)
{
    ShowError(result.Error.InnerException.Message);
}

Unfortunately, the InnerException property is null. So all we have to check is the text of the outer exception message which isn't being transferred to the client properly either.

It has been suggested that I need:

<customErrors mode="Off" />

in the web config file. I've tried this and it doesn't work.

It's also been suggested that I need:

[KnownType(typeof(OverMaxRowLimitException))]

on the data contract. Now unless I've put this in the wrong place, this also doesn't work.

I've also tried adding [Serializable] to the custom exception and replacing it with the general Exception. Neither of these worked either.

So, why is the InnerException property null. What am I missing?

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Take a look at this so question: http://stackoverflow.com/questions/5717231/faultexception-and-custom-exception-wcf – BlakeH Jan 28 '13 at 14:06
  • I think you should employ FaultContracts. – daryal Jan 28 '13 at 14:09
  • Have you tried this approach http://stackoverflow.com/questions/5766527/exception-handling-in-ria-service – Jehof Jan 28 '13 at 14:18
  • @Jehof - we are using a `DomainException`. – ChrisF Jan 28 '13 at 14:21
  • Have you tried to .share the OverMaxRotLimitException with your silverlight client project? – Jehof Jan 28 '13 at 14:30
  • Do you override the method OnError of your DomainService to set property `Error` of the `DomainServiceErrorInfo`? – Jehof Jan 28 '13 at 14:33
  • @Jehof - yes, I did share the exception and that didn't work either. Though I hadn't set the `[Serializable]` attribute at that point. No, we haven't overridden the `OnError` message. – ChrisF Jan 28 '13 at 14:34
  • Take a look at http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/95098d9f-95cf-42b0-be32-324ce434ec73 and http://stackoverflow.com/questions/7378601/ria-services-and-faultcontract. I think it is not possible to pass custom exceptions to silverlight clients – Jehof Jan 28 '13 at 15:11
  • @Jehof Good pointers. I never worked on silverlight before but i rather find this article interesting - http://mark.mymonster.nl/2011/02/10/make-use-of-wcf-faultcontracts-in-silverlight-clients/ – Flowerking Jan 28 '13 at 15:16

1 Answers1

0

I suppose you should be using

[FaultContract(typeof(OverMaxRowLimitException))]

for your operation contract for this. And your OverMaxRowLimitException should be serializable.

Also in the usage, I suppose proper way to throw the exception is to use

throw new FaultException<OverMaxRowLimitException>(yourException);

Flowerking
  • 2,551
  • 1
  • 20
  • 30