Dataset Serialize Outofmemoryexception
I've got a DataSet with about 250k Rows and 80 Columns causing StringBuilder to throw an OutOfMemoryException (@System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length. Serialize a DataSet. Serialize Raw JSON value. Serialize Unindented JSON. Serialize Conditional Property. Deserialize an Object. Deserialize a Collection.
Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHave a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
commented Nov 20, 2015
Hi all, I have a problem deserializing a JSON file of about 1GB. When I run the following code I get an out of memory exception: the exception is thrown by The serialization works well, here is the code I'm using Am I doing something wrong in the deserialization? Can you help suggesting a way to deserialize big json object? Thanks, Stefano |
commented Nov 25, 2015
Well if |
commented Nov 26, 2015
JsonReader already streams. Just load less data at once into memory. |
Dataset Serialize Outofmemoryexception In Excel
-->Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.
When implementing a serialization mechanism in an object-oriented environment, you have to make a number of tradeoffs between ease of use and flexibility. The process can be automated to a large extent, provided you are given sufficient control over the process. For example, situations may arise where simple binary serialization is not sufficient, or there might be a specific reason to decide which fields in a class need to be serialized. The following sections examine the robust serialization mechanism provided with .NET and highlight a number of important features that allow you to customize the process to meet your needs.
Note
The state of a UTF-8 or UTF-7 encoded object is not preserved if the object is serialized and deserialized using different .NET Framework versions.
Warning
Binary serialization can be dangerous. Never deserialize data from an untrusted source and never round-trip serialized data to systems not under your control.
As the nature of binary serialization allows the modification of private members inside an object and therefore changing the state of it, other serialization frameworks like JSON.NET which operate on the public API surface are recommended.
Binary serialization in .NET Core
.NET Core supports binary serialization with a subset of types. You can see the list of supported types in the Serializable types section. The defined set of types are guaranteed to be serializable between .NET Framework 4.5.1 and later versions and .NET Core 2.0 and later versions. Other .NET implementations, such as Mono, aren't officially supported but should also be working.
Serializable types
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException (available in .NET Core 2.0.4 and later versions)
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderInternalCompilerException (available in .NET Core 2.0.4 and later versions)
- System.AccessViolationException (available in .NET Core 2.0.4 and later versions)
- System.AggregateException (available in .NET Core 2.0.4 and later versions)
- System.AppDomainUnloadedException (available in .NET Core 2.0.4 and later versions)
- System.ApplicationException (available in .NET Core 2.0.4 and later versions)
- System.ArgumentException (available in .NET Core 2.0.4 and later versions)
- System.ArgumentNullException (available in .NET Core 2.0.4 and later versions)
- System.ArgumentOutOfRangeException (available in .NET Core 2.0.4 and later versions)
- System.ArithmeticException (available in .NET Core 2.0.4 and later versions)
- System.ArrayTypeMismatchException (available in .NET Core 2.0.4 and later versions)
- System.BadImageFormatException (available in .NET Core 2.0.4 and later versions)
- System.CannotUnloadAppDomainException (available in .NET Core 2.0.4 and later versions)
- System.Collections.Generic.KeyNotFoundException (available in .NET Core 2.0.4 and later versions)
System.Collections.Generic.NonRandomizedStringEqualityComparer
(available in .NET Core 2.0.4 and later versions)- System.ComponentModel.DataAnnotations.ValidationException (available in .NET Core 2.0.4 and later versions)
- System.ComponentModel.Design.CheckoutException (available in .NET Core 2.0.4 and later versions)
- System.ComponentModel.InvalidAsynchronousStateException (available in .NET Core 2.0.4 and later versions)
- System.ComponentModel.InvalidEnumArgumentException (available in .NET Core 2.0.4 and later versions)
- System.ComponentModel.LicenseException (available in .NET Core 2.0.4 and later versions, serialization from .NET Framework to .NET Core is not supported)
- System.ComponentModel.WarningException (available in .NET Core 2.0.4 and later versions)
- System.ComponentModel.Win32Exception (available in .NET Core 2.0.4 and later versions)
- System.Configuration.ConfigurationErrorsException (available in .NET Core 2.0.4 and later versions)
- System.Configuration.ConfigurationException (available in .NET Core 2.0.4 and later versions)
- System.Configuration.Provider.ProviderException (available in .NET Core 2.0.4 and later versions)
- System.Configuration.SettingsPropertyIsReadOnlyException (available in .NET Core 2.0.4 and later versions)
- System.Configuration.SettingsPropertyNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.Configuration.SettingsPropertyWrongTypeException (available in .NET Core 2.0.4 and later versions)
- System.ContextMarshalException (available in .NET Core 2.0.4 and later versions)
- System.DBNull (available in .NET Core 2.0.2 and later versions)
- System.Data.Common.DbException (available in .NET Core 2.0.4 and later versions)
- System.Data.ConstraintException (available in .NET Core 2.0.4 and later versions)
- System.Data.DBConcurrencyException (available in .NET Core 2.0.4 and later versions)
- System.Data.DataException (available in .NET Core 2.0.4 and later versions)
- System.Data.DataTable (unless you set RemotingFormat to SerializationFormat.Binary in which case it can only be exchanged with .NET Core 2.1 and later versions.)
- System.Data.DeletedRowInaccessibleException (available in .NET Core 2.0.4 and later versions)
- System.Data.DuplicateNameException (available in .NET Core 2.0.4 and later versions)
- System.Data.EvaluateException (available in .NET Core 2.0.4 and later versions)
- System.Data.InRowChangingEventException (available in .NET Core 2.0.4 and later versions)
- System.Data.InvalidConstraintException (available in .NET Core 2.0.4 and later versions)
- System.Data.InvalidExpressionException (available in .NET Core 2.0.4 and later versions)
- System.Data.MissingPrimaryKeyException (available in .NET Core 2.0.4 and later versions)
- System.Data.NoNullAllowedException (available in .NET Core 2.0.4 and later versions)
- System.Data.Odbc.OdbcException (available in .NET Core 2.0.4 and later versions)
- System.Data.OperationAbortedException (available in .NET Core 2.0.4 and later versions)
- System.Data.ReadOnlyException (available in .NET Core 2.0.4 and later versions)
- System.Data.RowNotInTableException (available in .NET Core 2.0.4 and later versions)
- System.Data.SqlClient.SqlException (available in .NET Core 2.0.4 and later versions, serialization from .NET Framework to .NET Core is not supported)
- System.Data.SqlTypes.SqlAlreadyFilledException (available in .NET Core 2.0.4 and later versions)
- System.Data.SqlTypes.SqlNotFilledException (available in .NET Core 2.0.4 and later versions)
- System.Data.SqlTypes.SqlNullValueException (available in .NET Core 2.0.4 and later versions)
- System.Data.SqlTypes.SqlTruncateException (available in .NET Core 2.0.4 and later versions)
- System.Data.SqlTypes.SqlTypeException (available in .NET Core 2.0.4 and later versions)
- System.Data.StrongTypingException (available in .NET Core 2.0.4 and later versions)
- System.Data.SyntaxErrorException (available in .NET Core 2.0.4 and later versions)
- System.Data.VersionNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.DataMisalignedException (available in .NET Core 2.0.4 and later versions)
System.Diagnostics.Contracts.ContractException
(available in .NET Core 2.0.4 and later versions)- System.Diagnostics.Tracing.EventSourceException (available in .NET Core 2.0.4 and later versions)
- System.IO.DirectoryNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.MultipleMatchesException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.NoMatchingPrincipalException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.PasswordException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.PrincipalException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.PrincipalExistsException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.PrincipalOperationException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.AccountManagement.PrincipalServerDownException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectExistsException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.ActiveDirectoryOperationException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.ActiveDirectoryServerDownException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.ForestTrustCollisionException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.ActiveDirectory.SyncFromAllServersOperationException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.DirectoryServicesCOMException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.Protocols.BerConversionException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.Protocols.DirectoryException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.Protocols.DirectoryOperationException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.Protocols.LdapException (available in .NET Core 2.0.4 and later versions)
- System.DirectoryServices.Protocols.TlsOperationException (available in .NET Core 2.0.4 and later versions)
- System.DivideByZeroException (available in .NET Core 2.0.4 and later versions)
- System.DllNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.DuplicateWaitObjectException (available in .NET Core 2.0.4 and later versions)
- System.EntryPointNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.EventArgs (available in .NET Core 2.0.6 and later versions)
- System.ExecutionEngineException (available in .NET Core 2.0.4 and later versions)
- System.FieldAccessException (available in .NET Core 2.0.4 and later versions)
- System.FormatException (available in .NET Core 2.0.4 and later versions)
- System.Globalization.CultureNotFoundException (available in .NET Core 2.0.4 and later versions)
System.IO.Compression.ZLibException
(available in .NET Core 2.0.4 and later versions)- System.IO.DriveNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.IO.EndOfStreamException (available in .NET Core 2.0.4 and later versions)
- System.IO.FileFormatException (available in .NET Core 2.0.4 and later versions)
- System.IO.FileLoadException (available in .NET Core 2.0.4 and later versions)
- System.IO.FileNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.IO.IOException (available in .NET Core 2.0.4 and later versions)
- System.IO.InternalBufferOverflowException (available in .NET Core 2.0.4 and later versions)
- System.IO.InvalidDataException (available in .NET Core 2.0.4 and later versions)
- System.IO.IsolatedStorage.IsolatedStorageException (available in .NET Core 2.0.4 and later versions)
- System.IO.PathTooLongException (available in .NET Core 2.0.4 and later versions)
- System.IndexOutOfRangeException (available in .NET Core 2.0.4 and later versions)
- System.InsufficientExecutionStackException (available in .NET Core 2.0.4 and later versions)
- System.InsufficientMemoryException (available in .NET Core 2.0.4 and later versions)
- System.InvalidCastException (available in .NET Core 2.0.4 and later versions)
- System.InvalidOperationException (available in .NET Core 2.0.4 and later versions)
- System.InvalidProgramException (available in .NET Core 2.0.4 and later versions)
- System.InvalidTimeZoneException (available in .NET Core 2.0.4 and later versions)
- System.MemberAccessException (available in .NET Core 2.0.4 and later versions)
- System.MethodAccessException (available in .NET Core 2.0.4 and later versions)
- System.MissingFieldException (available in .NET Core 2.0.4 and later versions)
- System.MissingMemberException (available in .NET Core 2.0.4 and later versions)
- System.MissingMethodException (available in .NET Core 2.0.4 and later versions)
- System.MulticastNotSupportedException (available in .NET Core 2.0.4 and later versions)
- System.Net.CookieException (available in .NET Core 2.0.4 and later versions)
- System.Net.HttpListenerException (available in .NET Core 2.0.4 and later versions)
- System.Net.Mail.SmtpException (available in .NET Core 2.0.4 and later versions)
- System.Net.Mail.SmtpFailedRecipientException (available in .NET Core 2.0.4 and later versions)
- System.Net.Mail.SmtpFailedRecipientsException (available in .NET Core 2.0.4 and later versions)
- System.Net.NetworkInformation.NetworkInformationException (available in .NET Core 2.0.4 and later versions)
- System.Net.NetworkInformation.PingException (available in .NET Core 2.0.4 and later versions)
- System.Net.ProtocolViolationException (available in .NET Core 2.0.4 and later versions)
- System.Net.Sockets.SocketException (available in .NET Core 2.0.4 and later versions)
- System.Net.WebException (available in .NET Core 2.0.4 and later versions)
- System.Net.WebSockets.WebSocketException (available in .NET Core 2.0.4 and later versions)
- System.NotFiniteNumberException (available in .NET Core 2.0.4 and later versions)
- System.NotImplementedException (available in .NET Core 2.0.4 and later versions)
- System.NotSupportedException (available in .NET Core 2.0.4 and later versions)
- System.NullReferenceException (available in .NET Core 2.0.4 and later versions)
- System.ObjectDisposedException (available in .NET Core 2.0.4 and later versions)
- System.OperationCanceledException (available in .NET Core 2.0.4 and later versions)
- System.OutOfMemoryException (available in .NET Core 2.0.4 and later versions)
- System.OverflowException (available in .NET Core 2.0.4 and later versions)
- System.PlatformNotSupportedException (available in .NET Core 2.0.4 and later versions)
- System.RankException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.AmbiguousMatchException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.CustomAttributeFormatException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.InvalidFilterCriteriaException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.ReflectionTypeLoadException (available in .NET Core 2.0.4 and later versions, serialization from .NET Framework to .NET Core is not supported)
- System.Reflection.TargetException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.TargetInvocationException (available in .NET Core 2.0.4 and later versions)
- System.Reflection.TargetParameterCountException (available in .NET Core 2.0.4 and later versions)
- System.Resources.MissingManifestResourceException (available in .NET Core 2.0.4 and later versions)
- System.Resources.MissingSatelliteAssemblyException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.CompilerServices.RuntimeWrappedException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.COMException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.ExternalException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.InvalidComObjectException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.InvalidOleVariantTypeException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.MarshalDirectiveException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.SEHException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.SafeArrayRankMismatchException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.InteropServices.SafeArrayTypeMismatchException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.Serialization.InvalidDataContractException (available in .NET Core 2.0.4 and later versions)
- System.Runtime.Serialization.SerializationException (available in .NET Core 2.0.4 and later versions)
- System.Security.AccessControl.PrivilegeNotHeldException (available in .NET Core 2.0.4 and later versions)
- System.Security.Authentication.AuthenticationException (available in .NET Core 2.0.4 and later versions)
- System.Security.Authentication.InvalidCredentialException (available in .NET Core 2.0.4 and later versions)
- System.Security.Cryptography.CryptographicException (available in .NET Core 2.0.4 and later versions)
- System.Security.Cryptography.CryptographicUnexpectedOperationException (available in .NET Core 2.0.4 and later versions)
System.Security.Cryptography.Xml.CryptoSignedXmlRecursionException
(available in .NET Core 2.0.4 and later versions)- System.Security.HostProtectionException (available in .NET Core 2.0.4 and later versions)
- System.Security.Policy.PolicyException (available in .NET Core 2.0.4 and later versions)
- System.Security.Principal.IdentityNotMappedException (available in .NET Core 2.0.4 and later versions)
- System.Security.SecurityException (available in .NET Core 2.0.4 and later versions, limited serialization data)
- System.Security.VerificationException (available in .NET Core 2.0.4 and later versions)
- System.Security.XmlSyntaxException (available in .NET Core 2.0.4 and later versions)
- System.ServiceProcess.TimeoutException (available in .NET Core 2.0.4 and later versions)
- System.StackOverflowException (available in .NET Core 2.0.4 and later versions)
- System.SystemException (available in .NET Core 2.0.4 and later versions)
- System.Text.DecoderFallbackException (available in .NET Core 2.0.4 and later versions)
- System.Text.EncoderFallbackException (available in .NET Core 2.0.4 and later versions)
- System.Text.RegularExpressions.RegexMatchTimeoutException (available in .NET Core 2.0.4 and later versions)
- System.Threading.AbandonedMutexException (available in .NET Core 2.0.4 and later versions)
- System.Threading.BarrierPostPhaseException (available in .NET Core 2.0.4 and later versions)
- System.Threading.LockRecursionException (available in .NET Core 2.0.4 and later versions)
- System.Threading.SemaphoreFullException (available in .NET Core 2.0.4 and later versions)
- System.Threading.SynchronizationLockException (available in .NET Core 2.0.4 and later versions)
- System.Threading.Tasks.TaskCanceledException (available in .NET Core 2.0.4 and later versions)
- System.Threading.Tasks.TaskSchedulerException (available in .NET Core 2.0.4 and later versions)
- System.Threading.ThreadAbortException (available in .NET Core 2.0.4 and later versions)
- System.Threading.ThreadInterruptedException (available in .NET Core 2.0.4 and later versions)
- System.Threading.ThreadStartException (available in .NET Core 2.0.4 and later versions)
- System.Threading.ThreadStateException (available in .NET Core 2.0.4 and later versions)
- System.Threading.WaitHandleCannotBeOpenedException (available in .NET Core 2.0.4 and later versions)
- System.TimeZoneNotFoundException (available in .NET Core 2.0.4 and later versions)
- System.TimeoutException (available in .NET Core 2.0.4 and later versions)
- System.Transactions.TransactionAbortedException (available in .NET Core 2.0.4 and later versions)
- System.Transactions.TransactionException (available in .NET Core 2.0.4 and later versions)
- System.Transactions.TransactionInDoubtException (available in .NET Core 2.0.4 and later versions)
- System.Transactions.TransactionManagerCommunicationException (available in .NET Core 2.0.4 and later versions)
- System.Transactions.TransactionPromotionException (available in .NET Core 2.0.4 and later versions)
- System.TypeAccessException (available in .NET Core 2.0.4 and later versions)
- System.TypeInitializationException (available in .NET Core 2.0.4 and later versions)
- System.TypeLoadException (available in .NET Core 2.0.4 and later versions)
- System.TypeUnloadedException (available in .NET Core 2.0.4 and later versions)
- System.UnauthorizedAccessException (available in .NET Core 2.0.4 and later versions)
- System.UriFormatException (available in .NET Core 2.0.4 and later versions)
- System.ValueTuple (not serializable in .NET Framework 4.7 and earlier versions)
- System.Xml.Schema.XmlSchemaException (available in .NET Core 2.0.4 and later versions)
- System.Xml.Schema.XmlSchemaInferenceException (available in .NET Core 2.0.4 and later versions)
- System.Xml.Schema.XmlSchemaValidationException (available in .NET Core 2.0.4 and later versions)
- System.Xml.XPath.XPathException (available in .NET Core 2.0.4 and later versions)
- System.Xml.XmlException (available in .NET Core 2.0.4 and later versions)
- System.Xml.Xsl.XsltCompileException (available in .NET Core 2.0.4 and later versions)
- System.Xml.Xsl.XsltException (available in .NET Core 2.0.4 and later versions)
In this section
Serialization Concepts
Discusses two scenarios where serialization is useful: when persisting data to storage and when passing objects across application domains.Basic Serialization
Describes how to use the binary and SOAP formatters to serialize objects.Selective Serialization
Describes how to prevent some members of a class from being serialized.Custom Serialization
Describes how to customize serialization for a class by using the ISerializable interface.Steps in the Serialization Process
Describes the course of action serialization takes when the Serialize method is called on a formatter.Version Tolerant Serialization
Explains how to create serializable types that can be modified over time without causing applications to throw exceptions.Serialization Guidelines
Provides some general guidelines for deciding when to serialize an object.
Reference
- System.Runtime.Serialization
Contains classes that can be used for serializing and deserializing objects.
Related sections
XML and SOAP Serialization
Describes the XML serialization mechanism that is included with the common language runtime.Security and Serialization
Describes the secure coding guidelines to follow when writing code that performs serialization..NET Remoting
Describes the various communications methods available in the .NET Framework for remote communications.XML Web Services Created Using ASP.NET and XML Web Service Clients
Provides topics that describe and explain how to program XML Web services created using ASP.NET.