System.OutOfMemoryException when Passing DataSet or DataTable in .Net Remoting

Friday, 22 July 2011 00:06 by ranjanbanerji

Recently noticed that an application was throwing a System.OutOfMemoryException.  A little bit of analysis determined that the exception was being thrown from the application/middle tier which is accessed by the client/web tier via .Net Remoting.  The error was occurring when trying to get a DataSet from the middle tier to the front end via a .Net Remoting interface.  At first I thought the DataSet was huge and using up too much memory.  But on further analysis I noticed that the code for retrieving the data and filling the DataSet worked just fine.  The OutOfMemoryException was occurring somewhere between leaving the remoting host and entering the web code.

That’s when it occurred to me that the problem maybe in the Binary Formatter.  A quick search on the web confirmed my hunch.  The error occurs during the serialization of the DataSet.  To prevent the problem use the RemotingFormat property.  This holds true for a DataTable too.