❔ BinaryFormatter does not serialize/deserialize the Tags of listview items
so i have a listview that i want to serialize and then desirialize. I store some values in the tags of each listview item. Problem is that after i clear the listview and deserialize the file, the tags of each listview item is gone. I don't know if this is a problem of the writer or the reader, but i guess its because of the writer skipping the tag property. How can i overcome this issue?
5 Replies
You shouldn't use
BinaryFormatter
anymore because of security reasons https://learn.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide
You also shouldn't use GUI controls as your data store. ListView
supports binding through DataSource
, although it's not as capable as modern frameworks.
Normally, I create persistence/serialization models. That is a class that contains all relevant properties that get serialized.
Then you map the data between the Model and ListViewItem
. And you serialize/deserialize with System.Text.Json / NewtonSoft / System.Xml.
You may be able to skip the mapping step if you use data binding via DataSource
. You can in XAML-based languages, but WinForms is not very good, especially in that area.thanks for the other solutions, but what about the BinaryFormatter? Do you know how i can achieve what i asked?
I don't help users write obviously bad code.
alright...
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.