Is C# .NET Serializer Atomic?
up vote
-2
down vote
favorite
Straight forward question. If CPU crashes during serialization, will the file be corrupted?
Example of .NET Serialization C#:
public bool TrySerializeToXML<T>(String FilePath, T t, XmlAttributeOverrides XmlAttributeOverrides = null)
{
lock (SerializationLock)
{
XmlSerializer Serializer = null;
try
{
if (XmlAttributeOverrides == null) Serializer = new XmlSerializer(t.GetType());
else Serializer = new XmlSerializer(t.GetType(), XmlAttributeOverrides);
using (TextWriter TextWriter = new StreamWriter(FilePath))
{
Serializer.Serialize(TextWriter, t);
}
}
catch
{
return false;
}
return true;
}
}
c# .net serialization
|
show 1 more comment
up vote
-2
down vote
favorite
Straight forward question. If CPU crashes during serialization, will the file be corrupted?
Example of .NET Serialization C#:
public bool TrySerializeToXML<T>(String FilePath, T t, XmlAttributeOverrides XmlAttributeOverrides = null)
{
lock (SerializationLock)
{
XmlSerializer Serializer = null;
try
{
if (XmlAttributeOverrides == null) Serializer = new XmlSerializer(t.GetType());
else Serializer = new XmlSerializer(t.GetType(), XmlAttributeOverrides);
using (TextWriter TextWriter = new StreamWriter(FilePath))
{
Serializer.Serialize(TextWriter, t);
}
}
catch
{
return false;
}
return true;
}
}
c# .net serialization
6
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
3
The file will be corru
– Hans Passant
Nov 22 at 0:10
1
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24
|
show 1 more comment
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
Straight forward question. If CPU crashes during serialization, will the file be corrupted?
Example of .NET Serialization C#:
public bool TrySerializeToXML<T>(String FilePath, T t, XmlAttributeOverrides XmlAttributeOverrides = null)
{
lock (SerializationLock)
{
XmlSerializer Serializer = null;
try
{
if (XmlAttributeOverrides == null) Serializer = new XmlSerializer(t.GetType());
else Serializer = new XmlSerializer(t.GetType(), XmlAttributeOverrides);
using (TextWriter TextWriter = new StreamWriter(FilePath))
{
Serializer.Serialize(TextWriter, t);
}
}
catch
{
return false;
}
return true;
}
}
c# .net serialization
Straight forward question. If CPU crashes during serialization, will the file be corrupted?
Example of .NET Serialization C#:
public bool TrySerializeToXML<T>(String FilePath, T t, XmlAttributeOverrides XmlAttributeOverrides = null)
{
lock (SerializationLock)
{
XmlSerializer Serializer = null;
try
{
if (XmlAttributeOverrides == null) Serializer = new XmlSerializer(t.GetType());
else Serializer = new XmlSerializer(t.GetType(), XmlAttributeOverrides);
using (TextWriter TextWriter = new StreamWriter(FilePath))
{
Serializer.Serialize(TextWriter, t);
}
}
catch
{
return false;
}
return true;
}
}
c# .net serialization
c# .net serialization
asked Nov 21 at 23:56
user1034912
73622335
73622335
6
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
3
The file will be corru
– Hans Passant
Nov 22 at 0:10
1
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24
|
show 1 more comment
6
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
3
The file will be corru
– Hans Passant
Nov 22 at 0:10
1
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24
6
6
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
3
3
The file will be corru
– Hans Passant
Nov 22 at 0:10
The file will be corru
– Hans Passant
Nov 22 at 0:10
1
1
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
XmlSerializer
works on a streamThat stream in this case is a
FileStream
A
FileStream
works on a flushable Buffer (of default 4k), meaning when the buffer reaches its max it will flush it to disk
If application crashes or serialisation error happens during serialisation you are likely to have no (or only partial data) flushed to disk
Also Atomic is debatably the wrong word to use here, either way it definitely is'nt Atomic
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
XmlSerializer
works on a streamThat stream in this case is a
FileStream
A
FileStream
works on a flushable Buffer (of default 4k), meaning when the buffer reaches its max it will flush it to disk
If application crashes or serialisation error happens during serialisation you are likely to have no (or only partial data) flushed to disk
Also Atomic is debatably the wrong word to use here, either way it definitely is'nt Atomic
add a comment |
up vote
2
down vote
accepted
XmlSerializer
works on a streamThat stream in this case is a
FileStream
A
FileStream
works on a flushable Buffer (of default 4k), meaning when the buffer reaches its max it will flush it to disk
If application crashes or serialisation error happens during serialisation you are likely to have no (or only partial data) flushed to disk
Also Atomic is debatably the wrong word to use here, either way it definitely is'nt Atomic
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
XmlSerializer
works on a streamThat stream in this case is a
FileStream
A
FileStream
works on a flushable Buffer (of default 4k), meaning when the buffer reaches its max it will flush it to disk
If application crashes or serialisation error happens during serialisation you are likely to have no (or only partial data) flushed to disk
Also Atomic is debatably the wrong word to use here, either way it definitely is'nt Atomic
XmlSerializer
works on a streamThat stream in this case is a
FileStream
A
FileStream
works on a flushable Buffer (of default 4k), meaning when the buffer reaches its max it will flush it to disk
If application crashes or serialisation error happens during serialisation you are likely to have no (or only partial data) flushed to disk
Also Atomic is debatably the wrong word to use here, either way it definitely is'nt Atomic
answered Nov 22 at 0:20
TheGeneral
25.9k53162
25.9k53162
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422097%2fis-c-sharp-net-serializer-atomic%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
The CPU never crashes, it merely tells you what you did wrong when you use C#. Use C++ if you favor an undiagnosable crash that nobody can help you with.
– Hans Passant
Nov 21 at 23:59
Thanks for the reply. Yes i understand... jeez.. common sense. I mean anything that happens during the operation will it cause the written file to be corrupted? or partially written
– user1034912
Nov 22 at 0:03
3
The file will be corru
– Hans Passant
Nov 22 at 0:10
1
That was a lot funnier then I intended it to be, sorry. My wife give me funny looks. I ought to be more helpful: use transactional saves. First save to a file with a temporary name. If nothing went wrong then rename it to the file it should be. The File.Replace() overload with three arguments is important to get this right.
– Hans Passant
Nov 22 at 0:21
There should be League Tables of comments of the day, i think that would win for today
– TheGeneral
Nov 22 at 0:24