EllanJiang/GameFramework · error · GameFrameworkException
Packet is invalid.
Error message
Packet is invalid.
What it means
Send<T> requires a non-null packet instance of a Packet-derived type. Passing null is rejected with GameFrameworkException (or NetworkChannelError with NetworkErrorCode.SendError). The packet is only enqueued here; serialization happens later in ProcessSend.
Solutions
- Null-check the packet before calling Send and log/return instead.
- Fix the packet construction code so it never returns null (throw at the factory instead).
- Register NetworkChannelError to convert the exception into an event-driven SendError.
- In generic send wrappers, add a where T : Packet, class constraint plus a null assertion.
Example fix
// before
channel.Send(BuildPacket()); // BuildPacket may return null
// after
var packet = BuildPacket();
if (packet != null) { channel.Send(packet); } Defensive patterns
Strategy: validation
Validate before calling
if (packet is null) throw new ArgumentNullException(nameof(packet)); channel.Send(packet);
Type guard
public static bool IsValidPacket(Packet p) => p != null;
Try / catch
try { channel.Send(packet); } catch (GameFrameworkException ex) when (ex.Message == "Packet is invalid.") { LogSendFailure(packet); } Prevention
- Null-check packet factories' return values
- Use nullable reference types (Packet?) to catch null flow at compile time
- Never pass the result of a fallible deserialize directly to Send
- Assert non-null in generic send helpers
When it happens
Trigger: Calling channel.Send<T>(null); passing the result of a factory/deserialize call that returned null; a variable typed Packet that was never assigned.
Common situations: Building packets from data that failed to load (null result); generic send helpers that forward possibly-null references; refactors that changed packet construction and silently produce null.
Related errors
- Packet header is invalid.
- Results is invalid.
- Network channel helper is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/49d8264d71553ac9.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Network/NetworkManager.NetworkChannelBase.cs:454
if (NetworkChannelError != null)
{
NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);
return;
}
throw new GameFrameworkException(errorMessage);
}
if (packet == null)
{
string errorMessage = "Packet is invalid.";
if (NetworkChannelError != null)
{
NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);
return;
}
throw new GameFrameworkException(errorMessage);
}
lock (m_SendPacketPool)
{
m_SendPacketPool.Enqueue(packet);
}
}
/// <summary>
/// 释放资源。
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>View on GitHub (pinned to d0c010b051)