P
Per Söderberg
Guest
Hello,
I have an error that I can't understand:
"System.Runtime.Serialization.SerializationException: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization."
I have made an application in VB.NET on Visual Studio 2017 that runs on a device with Windows 10 IoT operating system. The application works great when I start it in a normal way. However, it is necessary to start when the device is powered. And accordingly I put a shortcut in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" to the exe-file.
This is also working fine, until we test the device for crashes.
The application uses serialization and I make a file like this:
StringFile = "C:\Users\Public\data.stn"
Dim f As New FileStream(StringFile, IO.FileMode.Create)
Dim fo As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Try
fo.Serialize(f, variable)
more data....
f.Close()
Catch ex As Exception
EventLog("Exception when saving file data.stn." & ex.ToString)
End Try
when I run the application ands close the application I can see that the file is there and data is written in the file. The application also reads the file by using deserialization. And then when I turn of the device the autorun starts up but gives the error as above, and when I check the file data.stn its surprisingly empty...
Typically it works the first time the device is restarted but when it is run again it throws the exception. Actually it seems not depend on if the application is terminated correctly or when I turn it of while the application is running. The error message is displayed.
Is there any help to get to understand why the file is empty? I suppose the error is simply explaining that it reads nothing?
Much appreciate to get help with this!
Best Regards,
Per
Continue reading...
I have an error that I can't understand:
"System.Runtime.Serialization.SerializationException: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization."
I have made an application in VB.NET on Visual Studio 2017 that runs on a device with Windows 10 IoT operating system. The application works great when I start it in a normal way. However, it is necessary to start when the device is powered. And accordingly I put a shortcut in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" to the exe-file.
This is also working fine, until we test the device for crashes.
The application uses serialization and I make a file like this:
StringFile = "C:\Users\Public\data.stn"
Dim f As New FileStream(StringFile, IO.FileMode.Create)
Dim fo As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Try
fo.Serialize(f, variable)
more data....
f.Close()
Catch ex As Exception
EventLog("Exception when saving file data.stn." & ex.ToString)
End Try
when I run the application ands close the application I can see that the file is there and data is written in the file. The application also reads the file by using deserialization. And then when I turn of the device the autorun starts up but gives the error as above, and when I check the file data.stn its surprisingly empty...
Typically it works the first time the device is restarted but when it is run again it throws the exception. Actually it seems not depend on if the application is terminated correctly or when I turn it of while the application is running. The error message is displayed.
Is there any help to get to understand why the file is empty? I suppose the error is simply explaining that it reads nothing?
Much appreciate to get help with this!
Best Regards,
Per
Continue reading...