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

.net core binary serialization fails #95

Closed
chmorgan opened this issue May 31, 2019 · 8 comments
Closed

.net core binary serialization fails #95

chmorgan opened this issue May 31, 2019 · 8 comments

Comments

@chmorgan
Copy link
Collaborator

I'm working to convert the tests from a .net framework target to .net core so it is compatible with windows, Mac, and linux again without using mono. Binary serialization is a lot different in .net core, see https://github.com/dotnet/corefx/issues/23213 and when running as a .net core executable there are several failures like:

Message: System.Runtime.Serialization.SerializationException : Type 'System.Lazy`1[[PacketDotNet.PacketOrByteArraySegment, PacketDotNet, Version=0.30.1.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' is not marked as serializable.

should we drop these tests? What is the benefit/purpose of keeping these serialization tests working? @Phyxion any thoughts?

@PhyxionNL
Copy link
Collaborator

It seems Lazy isn't serializable anymore in .NET Core. I'm not sure how useful [Serializable] is in the library itself though (which should then be removed from everything), as I think you only want to save the underlying byte array (which can be used to reconstruct the packets again anyway).

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 31, 2019 via email

@PhyxionNL
Copy link
Collaborator

I was thinking about removing serialization tests and also the Serializable attribute from all classes in main project. I don't really see a good use case for that as the properties are based on byte array anyway and all you really need is to serialize is that. The only exception to the removal of all Serializable attributes is perhaps the ByteArraySegment as I can see the benefit of saving Length/Offset.

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 31, 2019 via email

@PhyxionNL
Copy link
Collaborator

PhyxionNL commented May 31, 2019

The tests are OK. Lazy just isn't serializable in .NET Core, which means that the packet serialization isn't going to work either (for the same reason). I think removing the Serializable attribute would be OK, I don't think many will use it as you're much better of serializing the ByteArraySegment or the underlying array.

The downside of simply removing all binary serialization tests is that most of these test methods are the only thing kind of validating the pcap files and their contained packet. So perhaps these should be changed to assert the expected value rather than comparing serialized vs deserialized. For example, this https://github.com/chmorgan/packetnet/blob/2f2f4208f2ee5efd707360bae969f64e7f198116/Test/PacketType/IPPacketTest.cs#L74 could check if ip.Protocol is ProtocolType.IPv4 (didn't check what it actually is). This is of course more work than removing these tests completely, but then there's at least some tests for packet correctness (expected values can be found in Wireshark). I don't have a lot of free time at the moment, so I hope this makes sense 👍

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 31, 2019 via email

@chmorgan
Copy link
Collaborator Author

chmorgan commented Jun 1, 2019

@Phyxion I took a look and didn't see anything that made sense to preserve. I did have one question. You flagged Echo as obsolete. Should we drop support for that option from TcpPacket.cs? Otherwise there are warnings printed during the compile. Thoughts?

@PhyxionNL
Copy link
Collaborator

The Echo was already flagged as Obsolete. I've not removed it yet because while RFC states it's obsolete, I'm not sure if it needs to be removed from the library. Perhaps it would be better to drop the Obsolete attribute instead. Also created PR #96 for these changes so it's easier to keep track on and allow AppVeyor to show results :)

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