Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary Serialization does not work #4

Open
winkert opened this issue Jun 7, 2017 · 3 comments
Open

Binary Serialization does not work #4

winkert opened this issue Jun 7, 2017 · 3 comments

Comments

@winkert
Copy link

winkert commented Jun 7, 2017

I am using this Date struct in a SortedDictionary and it is throwing a SerializationException. I see that this is using the ISerializable interface but does not have the serialization constructor. I added the [Serializable] attribute in order to get it to serialize but when it tries to deserialize I get the following exception:
The constructor to deserialize an object of type 'System.Date' was not found.

@winkert
Copy link
Author

winkert commented Jun 7, 2017

FYI: Adding the [Serializable] attribute and then adding the following constructor resolved this issue:
private Date(SerializationInfo info, StreamingContext context) { this._dt = DateTime.FromFileTime(info.GetInt64("ticks")); }

supersonicclay pushed a commit that referenced this issue Jun 13, 2017
@supersonicclay
Copy link
Owner

@winkert can you check the class I have in the binary branch?

@winkert
Copy link
Author

winkert commented Jun 13, 2017

@claycephas I realized as I was working on my own application that the constructor I put up is not correct. DateTime.FromFileTime() does not turn ticks to an accurate DateTime (I was struggling to understand why when I deserialized I was getting dates in the 3000s). There is a DateTime constructor that takes ticks and that is how I managed to get the information stored in the SerializationInfo (as ticks) to reload as a Date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants