Share via

Mysterious error, using the Autostart function

Anonymous
2019-10-16T11:56:54+00:00

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 and close the application correctly, 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 off 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, by crash, but when it is run again it throws the exception. Actually it seems to depend on if the application is terminated correctly or when I turn it off while the application is running. The latter gives the error message.

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

Windows for home | Windows 10 | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2019-10-18T08:59:12+00:00

    Hi Dave,

    Thanks for your concern!

    Well, I started programming in a language called Simula in 1979 at the Royal Institute of Technology here in Stockholm. But that was long before modern programming and we were fortunate to have an interactive teaching computer, in 1977 they still used hole cards!

    Anyway, these are obsolete knowledge in the world today and I try to keep up with the development despite the old knowledge! 

    Finally I believe that I have found the solution. It seems to be the write cache that empty the files and that causes the error message. The exception is thrown as the file is empty.

    Rather brutal, but I changed the settings and disconnected the cache write function. Now I have taken in and out the cord for an hour or so and no failure occur. I'm a bit concerned about if this slows down the prestanda, so it could be an idea to partion the disk and put the files there and  have the cache write unabled on that partion, but keep it for the C:!?

    Thanks to everyone who read this, and perhaps someone can get help from this solution idea!

    Cheers,

    Per

    Was this answer helpful?

    0 comments No comments
  2. DaveM121 889.6K Reputation points Independent Advisor
    2019-10-16T13:26:30+00:00

    Hi Per

    I have been coding for 20+ years, honestly you will get a suitable answer over on MSDN, the scope of that question is beyond this forum, it is no harm to leave that question also open on this forum at the same time . ..

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-10-16T13:22:24+00:00

    Hello Dave,

    Thanlks!

    The question has been transferred to that place. But I feel that it is about Windows and file handling.

    Best Regards,

    Per

    Was this answer helpful?

    0 comments No comments
  4. DaveM121 889.6K Reputation points Independent Advisor
    2019-10-16T12:41:54+00:00

    Hi Per

    Community is just a consumer forum, due to the scope of your question (VB / .Net Programming) can you please post this question to our sister forum on MSDN (the Developer Network) in the VB section (linked below)

    Over there you will have access to a host of VB coders experts and will get a knowledgeable and quick answer to this question . ..

    https://social.msdn.microsoft.com/Forums/vstudi...

    Was this answer helpful?

    0 comments No comments