Hello, I have a dataset with some datas (60 tables 30 relations) and that I must transfer it to another application (it is a cache file made when connected on a server and used locally when there is no connection possible). With .NET 4.6 (and so on) all is fine.
The dataset loads in less than 3 seconds. In .NET core 5 it is not possible.
so I have tried to use the WriteXML (with schema) bit it takes 28 seconds (really too much to be usable)
I have seen that there is a flag that can be put in the project <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
but when trying so serialize I have the error
Type 'System.Data.SimpleType' in Assembly 'System.Data.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
Is there something else I am missing? I can't find any serializer allowing me to serialize a complete dataset.
Using the EnforceConstraints
False
or importing the schema first and using ReadXML
without the infer doesn't change anything with the speed (still around 28 sec.) Thank you for your help Marc
The serialize code
ds.RemotingFormat = SerializationFormat.Binary;
IFormatter myFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
var myStream = new MemoryStream(); try { myFormatter.Serialize(myStream, ds);
Stream myStreamFina = new FileStream(FileName, FileMode.Create, FileAccess.Write);
var ZipStream = new GZipStream(myStreamFina, CompressionMode.Compress, false);
ZipStream.Write(myStream.GetBuffer(), 0, (int)myStream.Length);
ZipStream.Flush();
// Close the stream.
myStreamFina.Flush();
ZipStream.Close();
myStreamFina.Close();
} catch (Exception Ex) { ......... }
The ReadXML of the dataset.
var ds = new DataSet();
try { using (FileStream fs = new FileStream(FileName, FileMode.Open))
{ Stream s = new GZipStream(fs, CompressionMode.Decompress);
//Stream s = new GZipStream(fs, CompressionMode.Compress);
ds.ReadXml(s); s.Close(); }
} catch (Exception) { }