A debug only WCF Exception problem


When trying to pass Exception as Fault from server down to client, only in debug mode, the exception can’t be serialized, error message is:

System.Runtime.Serialization.SerializationException: Type ‘System.Collections.ListDictionaryInternal’ with data contract name ‘ArrayOfKeyValueOfanyTypeanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays’ is not expected. 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.

Reason is describe in reference 1, the the solution/work around from reference 2 is better. As reference 2 explained, this is a side effect from debugger. If debugging is disable in WCF host, we don’t get this problem.

Here is the post from MSDN describing how to enable the auto-attach WCF host process in debug mode. Note: the default debug flag for new WCF service is off.

      <!-- default was off, so auto-attach won't work. -->
      <compilation debug="true" /> 

What I figured out is developer also has to make sure in the WCF project property window, the servers url is correct in the web tab.


  1. http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/
  2. http://www.woutware.com/blog/post/Implementing-IErrorHandler-and-working-around-SerializationException.aspx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s