System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.ServiceModel.Channels.BufferManager.GCBuffe

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.ServiceModel.Channels.BufferManager.GCBuffe

Old forum URL: forums.lhotka.net/forums/t/11235.aspx


wasiuddin.786 posted on Friday, March 16, 2012

my application(SL4+EF4+Prisam+Unity+MVVM+CSLA+WCF)

some time when the records  are more i getting the error

u can find more details of error with an attachment

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

   at System.ServiceModel.Channels.BufferManager.GCBufferManager.TakeBuffer(Int32 bufferSize)

   at System.ServiceModel.Channels.BufferedOutputStream.AllocNextChunk(Int32 minimumChunkSize)

   at System.ServiceModel.Channels.BufferedOutputStream.WriteCore(Byte[] buffer, Int32 offset, Int32 size)

   at System.ServiceModel.Channels.BufferedOutputStream.Write(Byte[] buffer, Int32 offset, Int32 size)

   at System.Xml.XmlBinaryNodeWriter.FlushBuffer()

   at System.Xml.XmlStreamNodeWriter.WriteBytes(Byte[] byteBuffer, Int32 byteOffset, Int32 byteCount)

   at System.Xml.XmlBinaryNodeWriter.WriteBase64Text(Byte[] trailBytes, Int32 trailByteCount, Byte[] base64Buffer, Int32 base64Offset, Int32 base64Count)

   at System.Xml.XmlBaseWriter.WriteBase64(Byte[] buffer, Int32 offset, Int32 count)

   at System.Runtime.Serialization.XmlWriterDelegator.WriteBase64(Byte[] bytes)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteBase64(XmlWriterDelegator xmlWriter, Byte[] value, XmlDictionaryString name, XmlDictionaryString ns)

   at WriteCriteriaRequestToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )

   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)

   at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)

   at System.ServiceModel.Channels.BinaryMessageEncoderFactory.BinaryMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)

   at System.ServiceModel.Channels.HttpOutput.SendAsyncResult.SendWithoutChannelBindingToken()

   at System.ServiceModel.Channels.HttpOutput.BeginSend(TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest()

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.BeginSendRequest(Message message, TimeSpan timeout)

   at System.ServiceModel.Channels.RequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Dispatcher.RequestChannelBinder.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartSend(Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult result, Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin()

   at System.ServiceModel.ClientBase`1.ChannelBase`1.BeginInvoke(String methodName, Object[] args, AsyncCallback callback, Object state)

   at Csla.WcfPortal.WcfPortalClient.WcfPortalClientChannel.BeginCreate(CriteriaRequest request, AsyncCallback callback, Object asyncState)

   at Csla.WcfPortal.WcfPortalClient.Csla.WcfPortal.IWcfPortal.BeginCreate(CriteriaRequest request, AsyncCallback callback, Object asyncState)

   at Csla.WcfPortal.WcfPortalClient.OnBeginCreate(Object[] inValues, AsyncCallback callback, Object asyncState)

   at System.ServiceModel.ClientBase`1.InvokeAsync(BeginOperationDelegate beginOperationDelegate, Object[] inValues, EndOperationDelegate endOperationDelegate, SendOrPostCallback operationCompletedCallback, Object userState)

   at Csla.WcfPortal.WcfPortalClient.CreateAsync(CriteriaRequest request, Object userState)

   at Csla.WcfPortal.WcfPortalClient.CreateAsync(CriteriaRequest request)

   at Csla.DataPortalClient.WcfProxy`1.BeginCreate(Object criteria, Object userState)

   --- End of inner exception stack trace ---

   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

   at System.Delegate.DynamicInvokeImpl(Object[] args)

   at System.Delegate.DynamicInvoke(Object[] args)

   at Csla.DataPortalClient.SynchronizedWcfProxy`1.<>c__DisplayClassc.<RunSynchronized>b__b(Object o, RunWorkerCompletedEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)

   at System.ComponentModel.BackgroundWorker.<OnRun>b__1(Object state) Inner Exception : System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

   at System.ServiceModel.Channels.BufferManager.GCBufferManager.TakeBuffer(Int32 bufferSize)

   at System.ServiceModel.Channels.BufferedOutputStream.AllocNextChunk(Int32 minimumChunkSize)

   at System.ServiceModel.Channels.BufferedOutputStream.WriteCore(Byte[] buffer, Int32 offset, Int32 size)

   at System.ServiceModel.Channels.BufferedOutputStream.Write(Byte[] buffer, Int32 offset, Int32 size)

   at System.Xml.XmlBinaryNodeWriter.FlushBuffer()

   at System.Xml.XmlStreamNodeWriter.WriteBytes(Byte[] byteBuffer, Int32 byteOffset, Int32 byteCount)

   at System.Xml.XmlBinaryNodeWriter.WriteBase64Text(Byte[] trailBytes, Int32 trailByteCount, Byte[] base64Buffer, Int32 base64Offset, Int32 base64Count)

   at System.Xml.XmlBaseWriter.WriteBase64(Byte[] buffer, Int32 offset, Int32 count)

   at System.Runtime.Serialization.XmlWriterDelegator.WriteBase64(Byte[] bytes)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteBase64(XmlWriterDelegator xmlWriter, Byte[] value, XmlDictionaryString name, XmlDictionaryString ns)

   at WriteCriteriaRequestToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )

   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)

   at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)

   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)

   at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)

   at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)

   at System.ServiceModel.Channels.BinaryMessageEncoderFactory.BinaryMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)

   at System.ServiceModel.Channels.HttpOutput.SendAsyncResult.SendWithoutChannelBindingToken()

   at System.ServiceModel.Channels.HttpOutput.BeginSend(TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest()

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.BeginSendRequest(Message message, TimeSpan timeout)

   at System.ServiceModel.Channels.RequestChannel.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Dispatcher.RequestChannelBinder.BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, Object state)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartSend(Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult result, Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(Boolean completedSynchronously)

   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin()

   at System.ServiceModel.ClientBase`1.ChannelBase`1.BeginInvoke(String methodName, Object[] args, AsyncCallback callback, Object state)

   at Csla.WcfPortal.WcfPortalClient.WcfPortalClientChannel.BeginCreate(CriteriaRequest request, AsyncCallback callback, Object asyncState)

   at Csla.WcfPortal.WcfPortalClient.Csla.WcfPortal.IWcfPortal.BeginCreate(CriteriaRequest request, AsyncCallback callback, Object asyncState)

   at Csla.WcfPortal.WcfPortalClient.OnBeginCreate(Object[] inValues, AsyncCallback callback, Object asyncState)

   at System.ServiceModel.ClientBase`1.InvokeAsync(BeginOperationDelegate beginOperationDelegate, Object[] inValues, EndOperationDelegate endOperationDelegate, SendOrPostCallback operationCompletedCallback, Object userState)

   at Csla.WcfPortal.WcfPortalClient.CreateAsync(CriteriaRequest request, Object userState)

   at Csla.WcfPortal.WcfPortalClient.CreateAsync(CriteriaRequest request)

   at Csla.DataPortalClient.WcfProxy`1.BeginCreate(Object criteria, Object userState)

RockfordLhotka replied on Friday, March 16, 2012

The two immediate possibilities that come to mind:

  1. Your object graph is massive, and serializing it literally does cause the DataContractSerializer to hit some memory limit
  2. Your object graph has a circular reference, and serializing it causes an infinite loop of serialization that results in consumption of all memory

I'm not entirely sure the second item is actually possible, because the MobileFormatter should be flattening the object graph into a list, and converting all object references into numeric position values before serialization begins.

So you might want to upgrade to version 4.3 and see if the new binary reader/writer solves the problem. They result in much smaller serialization results, and therefore might avoid the issue.

Copyright (c) Marimer LLC