I have this code. It gives me an error :
Destination array is not long enough to copy all the items in the collection. Check array index and length.
I thought that it was because of using a dictionary, so I switched it to ConcurrentDictionary
, but the error is still here.
private void SaverCallback()
{
AddThread("Main Thread");
const string path = "milestone";
while (!stop)
{
ConcurrentDictionary<string, object> milestone = new ConcurrentDictionary<string, object>();
milestone.TryAdd("Jobs", JobQueue.Queue.MainQueue);
milestone.TryAdd("Locked Jobs", JobQueue.Queue.LockedQueue);
again: try {
using (FileStream writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
BinaryFormatter formater = new BinaryFormatter();
formater.Serialize(writingStream, milestone);
writingStream.Flush();
Logger.Debug("Status saved");
}
}
catch(Exception e)
{
Logger.Error($"Milestone exception: {e.Message}");
goto again;
}
this.WaitTime(60000);
}
RemoveThread();
}
UPD:
Destination array is not long enough to copy all the items in the collection. Check array index and length. and at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary
2.CopyTo(KeyValuePair
2[] array, Int32 index) at System.Collections.Generic.Dictionary`2.GetObjectData(SerializationInfo info, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, Object data) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at AggregateRunner.Enteties.Saver.SaverCallback()
goto
. it indicates a major design issue. the only languages where jumps are allowed are IL and ASM – Sebastian LJobQueue.Queue.MainQueue
andJobQueue.Queue.LockedQueue
? – Matthew Watsonmilestone
? If so, perhaps something bad is happening during that process. – Matthew Watson