Why DataContractSerializer cause exception. Can I fix the broken xml file manually?
Dear all:
I have some questions when using DataContractSerializer.
1. Does mult开发者_JAVA百科iple threads to write different files at the same time increase the performance?
I tested and the conclusion is decrease the performance...... But sometimes get the exception as question 2.
2. I create two threads to do the serialize different object into different files. Sometimes I got the exception as below:
"An unhandled exception of type 'System.InvalidOperationException'
Additional information: Token StartElement in state EndRootElement would result in an invalid XML document.
Make sure that the ConformanceLevel setting is set to ConformanceLevel.
Fragment or ConformanceLevel.Auto if you want to write an XML fragment."
I googled for handle this exception but cannot understand what is the root cause....
And if the exception happened. I met the problem as question 3.
3. If the XML is not a valid file( only have partial content but suddenly end of file), the DeSerialize process may cause exception...v It means all the information lost due to the invalid XML. Is there any way to recover this XML file. I'm afraid of losing all the information by the exception happened.
Thanks.
Dear all: Thanks for reply.
For 3, sometime the exception cause the file being empty. I have no opportunity to fix the file.
It's very dangerous if the exception happened for me.
For 2. I paste the code snippet as the link http://nopaste.csie.org/c4711#form
I use the different file to serialize and serialize different memory.
I found if exception happened, the file will be empty, even exception did not happen, the files are also not complete. Deserialize will cause exception....
I have no idea why this happened not always but very often.
Thanks.
1 - usually not; most times you will be blocked on IO, so unless you have enough IO bandwidth to satisfy all the threads, it won't help; WP7 is going to have a slightly different profile here, but IO is still always a premium
2/3 - we'd need to see some code to understand what is happening
精彩评论