WCF- Type ApplicationException with data contract name is not expected RRS feed

  • Question

  • I get the following exception:

     Type 'System.ApplicationException' with data contract name 'ApplicationException:' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

    I'm using GzipMessageEncoder, with implementation similar to the one mentioned here:

    The mentioned exception happenes in the first line:

        var buffer = _innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);

    of method

        public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager,
    int messageOffset)

    I've actually succeeded in reproducing the problem.
    If the delivered message contains exception, the error occurs, for example:

    var exc = new MyException(MyMessages.GeneralException, new List<MyParameter>
                    new MyParameter
                        Value = new ApplicationException()
                throw exc;

    I tried to do someting like:

        public class MyException : ApplicationException, IMyException

    but it still reproduces the same error.

    I've read about DataContract Resolver
    but I'm not sure how to adapt it to my case of Gzip implaemntation.

    I want somehow to deliver the exception on the wire (I know about WCF faults, but again, this code is called via configuration, so I doubt if I can use them).
    Any suggestions, please?

    • Edited by DK1987 Tuesday, July 21, 2015 3:26 PM
    Tuesday, July 21, 2015 3:24 PM