serialization - Intermittent Exception when Deserializing Data Using Memory Mapped Files in C# -
i'm getting exception when deserializing data using memory mapped files , i'm not quite sure why.
here's important parts of code:
//the class serializing [protocontract] public class result { [protomember(1)] private dictionary<string, string> _errordict; [protomember(2)] public dictionary<string, string> resultsdict { get; set; } private readonly pipestream _stream; private readonly streamwriter _writer; private memorymappedfile _mmf; public result() { _errordict = new dictionary<string, string>(); } public result(string pipehandle) { _errordict = new dictionary<string, string>(); resultsdict = new dictionary<string, string>(); if (pipehandle != null) { _stream = new anonymouspipeclientstream(pipedirection.out, pipehandle); _writer = new streamwriter(_stream) { autoflush = true }; } } public void adderror(string file, string error) { _errordict.add(file, error); } public void serialize() { _mmf = memorymappedfile.createoropen(frconfig.config_file, frconfig.config_file_size); using (memorymappedviewstream stream = _mmf.createviewstream()) { serializer.serializewithlengthprefix(stream, this, prefixstyle.base128); stream.flush(); } } public static result deserialize() { using (memorymappedfile mmf = memorymappedfile.openexisting(frconfig.config_file)) { using (memorymappedviewstream stream = mmf.createviewstream()) { return serializer.deserializewithlengthprefix<frresult>(stream, prefixstyle.base128); } } } /// <summary> /// writes progress information pipe. /// </summary> public void writetostream(object s) { if (_stream == null || _writer == null) return; _writer.writeline(s); _stream.waitforpipedrain(); } } //on main thread: private static void main() { //spawn child process //after returning child process... var r = frresult.deserialize(); } //on child process static void main(string[] args) { var result = new frresult(pipehandle); //perform processing result.serialize() }
when making call deserialize method after returning child process, somethimes following exception:
filenotfoundexception occured exception thrown: 'system.io.filenotfoundexception' in system.core.dll additional information: unable find specified file.
system.io.filenotfoundexception occurred
hresult=-2147024894
message=unable find specified file.
source=system.core
stacktrace:
@ system.io.__error.winioerror(int32 errorcode, string maybefullpath)
innerexception:
i'm not sure why error gets thrown nor best way fix this.