I am seeing odd behavior when attempting to deserialize a relatively large object graph ~10000 rows with 6 columns on it. I'm sure that the problem is that there is a serialization exception when attempting to deserialize this array from the service back to the client. It works fine for datasets of less then 9000 objects and the console window shows a first chance SerializationException followed by a CommunicationException. I am self hosting this service within a console app since I am using it to integrate with a third party api. My first question is does anyone know have any idea what could be causing this serilization exception?
I am configuring the binding in code the following way on both the client and the server and I think I've turned it to the max possible.
public static NetTcpBinding CreateStandardNetTcpBinding()
{
NetTcpBinding b = new NetTcpBinding(SecurityMode.None);
b.OpenTimeout = new TimeSpan(0, 5, 0);
b.ReceiveTimeout = new TimeSpan(0, 5, 0);
b.SendTimeout = new TimeSpan(0, 5, 0);
b.MaxReceivedMessageSize = Int32.MaxValue;
b.MaxBufferSize =(int) b.MaxReceivedMessageSize;
b.MaxBufferPoolSize = (int) b.MaxReceivedMessageSize;
b.TransferMode= TransferMode.Buffered;
b.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
b.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
b.ReaderQuotas.MaxBytesPerRead = 4096;
b.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
b.ReaderQuotas.MaxDepth = 32;
return b;
}
My second question is why is this exception not raising the ProvideFault method on the IErrorHandler interface. When I raise an exception from within the ServiceOperation the ProvideFault method does get raised. Aren't WCF framework exceptions also caught by IErrorHandler? But for this particular problem WCF seems to close the channel abruptly/instantly after catching the serialization exception (so timeout is out of the question).
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.8939894'.
My third question is does anyone know how to programmically add a WCF trace listener? I work in a plugin environment where the application doesn't have a dedicated app.config file.
Thanks!
---EDIT---
Yup that was the problem. The default is about 64K which I was hitting. A solution is to
set the MaxItemsInObjectGraph value in the servicebehavior attribute [ServiceBehavior(IncludeExceptionDetailInFaults = true, MaxItemsInObjectGraph = int.MaxValue)]
and set the size on the client on the client like so...
var behaviors = Endpoint.Contract.Operations
.Select(o => o.Behaviors.Find<DataContractSerializerOperationBehavior>())
.Where(behavior => behavior != null);
foreach (var serializationBehavior in behaviors)
{
serializationBehavior.MaxItemsInObjectGraph = int.MaxValue;
}