I ran into a very unpleasant problem that I cannot determine.
I am launching a very large ASP.Net application for business containing many thousands of objects; It uses in-memory serialization / deserialization with a MemoryStream to clone the application state (insurance contracts) and transfer it to other modules. He worked perfectly for many years. Now sometimes not systematically ; in serialization, it throws an exception
The decimal byte array constructor requires a four-byte array containing valid decimal bytes.
Running the same application with the same data, 3 times out of 5 it works. I have included all CLR exceptions, Debugging - Exceptions - CLR Exception - Enabled, so I assume that if an incorrect initialization / assignment in the decimal field occurs, the program should stop. This is not happening. I tried to separate serialization into more elementary objects, but it is very difficult to try to determine the field causing the problem. From the working version in production and this, I switched from .Net 3.5 to .NET 4.0 and successive changes were made in the user interface part, and not in the business part. Patiently I will go through all the changes.
It looks like old-fashioned C problems, when char *p writes where it should not, and only during serialization, when it analyzes all the data, the problem crashes.
Is this possible in a managed .Net environment? The application is huge, but I do not see the abnormal pace of memory. What can be a way to debug and track a problem?
Below is the stacktrace part
[ArgumentException: Decimal byte array constructor requires an array of length four containing valid decimal bytes.] System.Decimal.OnSerializing(StreamingContext ctx) +260 [SerializationException: Value was either too large or too small for a Decimal.] System.Decimal.OnSerializing(StreamingContext ctx) +6108865 System.Runtime.Serialization.SerializationEvents.InvokeOnSerializing(Object obj, StreamingContext context) +341 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +448 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +969 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +1016 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +319 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) +17 Allianz.Framework.Helpers.BinaryUtilities.SerializeCompressObject(Object obj) in D:\SVN\SUV\branches\SUVKendo\DotNet\Framework\Allianz.Framework.Helpers\BinaryUtilities.cs:98 Allianz.Framework.Session.State.BusinessLayer.BLState.SaveNewState(State state) in
Sorry for the long history and the vague question, I will really appreciate any help.