Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:05:56+00:00 2026-06-05T04:05:56+00:00

I have a .NET 4 WCF service that is sending the client some big

  • 0

I have a .NET 4 WCF service that is sending the client some big objects (~115Mb) that get deserialized by the client. The first time the object comes in it deserializes fine. However, all subsequent calls throw an OutOfMemoryException. I’ve checked to make sure that all of my IDisposables are wrapped in using blocks. I’ve looked at the other questions similar to this such as BinaryFormatter outofmemory exception deserialization
and Deserialize from MemoryStream throws OutOfMemory exception in C#
. I’ve tried some of the solutions that people have recommended including using Simon Hewitt’s Optimized Serializer. However, in the end, he still relies on BinaryFormatter for deserializing objects.

I caught the OutOfMemoryException and looked at the stack trace (see below). The trace appears to originate from an issue with the memory utilization in the StringBuilder class. I’ve read other articles about how StringBuilder can cause memory problems due to the (length * 2) algorithm they use when more space is needed.

at System.Text.StringBuilder.ToString()    
at System.IO.BinaryReader.ReadString()    
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectString(BinaryHeaderEnum binaryHeaderEnum)    
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()    
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)    
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)    
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)

Is there a way to get BinaryFormatter to work differently and not use StringBuilder or is there a good alternative to BinaryFormatter that manages memory better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:05:56+00:00Added an answer on June 5, 2026 at 4:05 am

    I wouldn’t recommend using BinaryFormatter for anything that size (in fact it would probably be a lot smaller if you weren’t using binaryformatter). If it is fairly simple data such as tabular data or with some constraints like no circular references and so on, then rolling your own binary serialization with a simple binary writer, or using some off the shelf serializer like protobuf-net or json.net should be more compact and significantly faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wcf service that uses the .net System.AddIns framework to load assemblies
I have a WCF service that I need to call in a ASP.NET web
I have an ASP.NET page that calls to a WCF service. This WCF service
I have an asp.net 4 application that hosts a WCF REST service via WebServiceHost...
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have a REST service consumed by a .Net WCF client. When an error
I have a WCF service hosted that is returning a byte[] of protobuf-net serialized
Lets say I have a WCF service that a client can use to receive
I have a WCF service that uses ODP.NET to read data from an Oracle
I have self hosted net tcp WCF service that exposes two methods and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.