RevenantX/LiteNetLib

Irregular error with NetPacketProcessor on sending nested with null value

berta2 opened this issue · 5 comments

berta2 commented

Hi RevenantX,

first of all thanks for your great work, I have already implemented some projects with LiteNetLib.

Now I have encountered a problem that I can not explain.

I have an Employee class that contains a Person class and a Department class. All of them are INetSerializeable.
If I put them in an EmployeePacket class and add a Person class to the Employee but not Department class, the send operation sometimes works and sometimes not.

Error message:

System.ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name"
@ Deserialize() on Department class -> DepartmentId = reader.GetInt();

My question now is, why does this sometimes work 10 times in a row without error message?
Sometimes it goes wrong after the first time. And sometimes it does not work at the first send.

If it would never work, it would be clear that you can not send a null value. But exactly this seems to work. Why not always?

Here I have an working example for you:
https://github.com/berta2/LiteNetLibTest

Library version: 0.9.5.2

Framework: .NET 6

OS: Windows

@berta2 cannot reproduce in your project. Maybe you somewhere using multithreading?

@berta2 any updates?

I had a similar error that occured with higher frequency packets, where only some failed, in my case it seemed to be for the (Try)GetString() method. I tried replacing the null check in NetDataWriter.Put(string) with string.IsNullorEmpty(x), because the ones that i pass in can only ever be string.Empty. This seemed to fix the error for some reason, but it could just have been a placebo.

@berta2 try latest version. There can be fix.

Duplicate of #516