none
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:http://schemas.datacontract.org/2004/07/System' 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:
    http://lokad-sdk.googlecode.com/svn/trunk/dot-net/Api/Lokad.ServiceModel/Channels/GZipMessageEncoder.cs

    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:

         
     [KnownType(typeof(ApplicationException))]
        [KnownType(typeof(MyParameter))]
        [KnownType(typeof(MyMessages))]
        public class MyException : ApplicationException, IMyException



    but it still reproduces the same error.

    I've read about DataContract Resolver 
    https://msdn.microsoft.com/en-us/library/ee358759(v=vs.110).aspx
    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

Answers