G
Guest
Hi to all,
I am getting this System.OutOfMemoryException calling the
Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method.
The type of <stream> is IO.MemoryStream
=====Exception:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException'
was
thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BinaryWriter.Write(Double value)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteValue(I
nternalPrimitiveTypeE code, Object value)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteMember(
NameInfo memberNameInfo, NameInfo typeNameInfo, Object value)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteKnownValu
eClass(NameInfo memberNameInfo, NameInfo typeNameInfo, Object data)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMembers(N
ameInfo memberNameInfo, NameInfo memberTypeNameInfo, Object memberData,
WriteObj
ectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMemberSet
up(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo
typeNameInfo, S
tring memberName, Type memberType, Object memberData, WriteObjectInfo
memberObje
ctInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj
ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, String[]
mem
berNames, Type[] memberTypes, Object[] memberData, WriteObjectInfo[]
memberObjec
tInfos)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj
ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje
ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S
tream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S
tream serializationStream, Object graph)
at SerializationBenchmark.Module1.Main() in C:\Develop\Projects\Visual
Studio
2005\SerializationBenchmark\SerializationBenchmark\Module1.vb:line 41
=============
After building a benchmark application to reproduce the error (building
progressively larger objects to serialize until getting the error).
To understand the problem, I collected the following informations:
Serialization stream lenght (before exception is thrown) 16,777,214 Bytes
Allocated memory 1,028,914,416 Bytes
[to get the memory I called GC.GetTotalMemory(False)]
Please note my system is a x64 workstation with 6 GB RAM (and Windows Server
2003 R2 SP2 Enterprise). When the exception was thrown the total load of the
system was about 4162 MB.
The application configuration targets specifically x86 platform.
Can anybody explain me this behaviour and how to workaround it? I cannot
understand the why of the exception, since the lenght of the stream is lower
than the Int32.MaxValue and I still have free RAM.
Any help will be appreciated.
Thank you
I am getting this System.OutOfMemoryException calling the
Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method.
The type of <stream> is IO.MemoryStream
=====Exception:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException'
was
thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BinaryWriter.Write(Double value)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteValue(I
nternalPrimitiveTypeE code, Object value)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteMember(
NameInfo memberNameInfo, NameInfo typeNameInfo, Object value)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteKnownValu
eClass(NameInfo memberNameInfo, NameInfo typeNameInfo, Object data)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMembers(N
ameInfo memberNameInfo, NameInfo memberTypeNameInfo, Object memberData,
WriteObj
ectInfo objectInfo, NameInfo typeNameInfo, WriteObjectInfo memberObjectInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteMemberSet
up(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo
typeNameInfo, S
tring memberName, Type memberType, Object memberData, WriteObjectInfo
memberObje
ctInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj
ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, String[]
mem
berNames, Type[] memberTypes, Object[] memberData, WriteObjectInfo[]
memberObjec
tInfos)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObj
ectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje
ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S
tream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S
tream serializationStream, Object graph)
at SerializationBenchmark.Module1.Main() in C:\Develop\Projects\Visual
Studio
2005\SerializationBenchmark\SerializationBenchmark\Module1.vb:line 41
=============
After building a benchmark application to reproduce the error (building
progressively larger objects to serialize until getting the error).
To understand the problem, I collected the following informations:
Serialization stream lenght (before exception is thrown) 16,777,214 Bytes
Allocated memory 1,028,914,416 Bytes
[to get the memory I called GC.GetTotalMemory(False)]
Please note my system is a x64 workstation with 6 GB RAM (and Windows Server
2003 R2 SP2 Enterprise). When the exception was thrown the total load of the
system was about 4162 MB.
The application configuration targets specifically x86 platform.
Can anybody explain me this behaviour and how to workaround it? I cannot
understand the why of the exception, since the lenght of the stream is lower
than the Int32.MaxValue and I still have free RAM.
Any help will be appreciated.
Thank you