Will XmlSerializer ever create empty documents

后端 未结 2 587
不知归路
不知归路 2021-01-22 14:00

Alright, The following code I\'ve had in production for over a year with no changes. It has been working quite well. Within the past month more then a handful machines report th

2条回答
  •  伪装坚强ぢ
    2021-01-22 14:32

    We've encountered this problem several times at $WORK, with the symptom being an empty file of the correct size but filled with zero bytes.

    The solution we found was to set the WriteThrough value on the FileStream:

    using (Stream file = new FileStream(settingTemp, FileMode.Create,
                                       FileAccess.Write, FileShare.None,
                                       0x1000, FileOptions.WriteThrough))
    {
       using (StreamWriter sw = new StreamWriter(file))
       {
          ...
       }
    }
    

提交回复
热议问题