Strange 'Safe Handle Has Been Closed' error on large objects

Strange 'Safe Handle Has Been Closed' error on large objects

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


ticklemymonkey posted on Friday, February 15, 2008

I have a large object tree.  This consists of :

a BusinessBase (1 item)
   - b BusinessListBase (1 item)
      - c BusinessBase   (>1000 items)
         - d BusinessListBase (1 per above line item c)
            - e BusinessBase (~5-10 per line item c)

The application is a Windows Forms application and uses .Net Remoting to communicate with the data portal tier.

When I try to save the structure above, I recieve an ObjectDisposedException: 'Safe Handle Has Been Closed'

This does not occur elsewhere in the application, and I think it occurs during the serialization process.  It also does not occur when the same object has a small number of line items c.

I have included all exception information below, and also included a screen shot of the exception message as it appears in my application at this time.

If anyone can help me shed some light on the source of the problem, it would be much appreciated!

Will Houston

[System.ObjectDisposedException]: {"Safe handle has been closed"}

Data: {System.Collections.ListDictionaryInternal}

HelpLink: null

InnerException: null

Message: "Safe handle has been closed"

Source: "mscorlib"

StackTrace: "\r\nServer stack trace: \r\n at System.Net.UnsafeNclNativeMethods.OSSOCK.setsockopt(SafeCloseSocket socketHandle, SocketOptionLevel optionLevel, SocketOptionName optionName, Int32& optionValue, Int32 optionLength)\r\n at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue, Boolean silent)\r\n at System.Net.Sockets.NetworkStream.SetSocketTimeoutOption(SocketShutdown mode, Int32 timeout, Boolean silent)\r\n at System.Net.ConnectStream.SafeSetSocketTimeout(SocketShutdown mode)\r\n at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)\r\n at System.IO.BinaryReader.ReadBytes(Int32 count)\r\n at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)\r\n at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializationHeaderRecord()\r\n at System.Runtime.Se

rialization.Formatters.Binary.__BinaryParser.Run()\r\n at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)\r\n at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)\r\n\r\nException rethrown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at Csla.Server.IDataPortalServer.Update(Objec

t obj, DataPortalContext context)\r\n at Csla.DataPortalClient.RemotingProxy.Update(Object obj, DataPortalContext context) in D:\\Samples\\csla302cs\\cslacs\\Csla\\DataPortal\\Client\\RemotingProxy.cs:line 124\r\n at Csla.DataPortal.Update(Object obj) in D:\\Samples\\csla302cs\\cslacs\\Csla\\DataPortal\\Client\\DataPortal.cs:line 360\r\n at Csla.DataPortal.Update[T](T obj) in D:\\Samples\\csla302cs\\cslacs\\Csla\\DataPortal\\Client\\DataPortal.cs:line 301\r\n at Csla.BusinessBase`1.Save() in D:\\Samples\\csla302cs\\cslacs\\Csla\\BusinessBase.cs:line 154\r\n at erac.VACA.Library.ResidualList.Save() in D:\\VA Cost Analysis\\AppCode\\VACA\\VACA.Library\\ResidualList.cs:line 1531\r\n at erac.VACAWindows.ResidualListForm.RebindUI(Boolean saveObject, Boolean rebind, Boolean doNameCheck) in D:\\VA Cost Analysis\\AppCode\\VACA\\VACAWindows\\ResidualListForm.cs:line 344"

TargetSite: {Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)}

RockfordLhotka replied on Sunday, February 17, 2008

I'd guess that the BinaryFormatter has a maximum limit on the number of objects allowed in a graph, and you've probably exceeded that amount.

I know the WCF formatters have a configuration option you can set to up their maximum limit. I don't know if there's a comparable config option for the BinaryFormatter.

Copyright (c) Marimer LLC