SignalR/SignalR · error · ArgumentNullException
serializer
Error message
serializer
What it means
JsonSerializerExtensions.Parse<T>(string) is an extension method on JsonSerializer; C# extension methods are invoked as static calls, so a null receiver does not NRE at the call site — the method's explicit guard is what catches it. It then opens a StringReader and deserializes, requiring a real serializer.
Source
Thrown at src/Microsoft.AspNet.SignalR.Core/Json/JsonSerializerExtensions.cs:29
namespace Microsoft.AspNet.SignalR.Json
{
/// <summary>
/// Extensions for <see cref="JsonSerializer"/>.
/// </summary>
public static class JsonSerializerExtensions
{
/// <summary>
/// Deserializes the JSON to a .NET object.
/// </summary>
/// <param name="serializer">The serializer</param>
/// <typeparam name="T">The <see cref="System.Type"/> of object being deserialized.</typeparam>
/// <param name="json">The JSON to deserialize</param>
/// <returns>The deserialized object from the JSON string.</returns>
public static T Parse<T>(this JsonSerializer serializer, string json)
{
if (serializer == null)
{
throw new ArgumentNullException("serializer");
}
using (var reader = new StringReader(json))
{
return (T)serializer.Deserialize(reader, typeof(T));
}
}
/// <summary>
/// Deserializes the JSON to a .NET object.
/// </summary>
/// <param name="serializer">The serializer</param>
/// <typeparam name="T">The <see cref="System.Type"/> of object being deserialized.</typeparam>
/// <param name="jsonBuffer">The JSON buffer to deserialize</param>
/// <param name="encoding">The encoding to use.</param>
/// <returns>The deserialized object from the JSON string.</returns>
public static T Parse<T>(this JsonSerializer serializer, ArraySegment<byte> jsonBuffer, Encoding encoding)
{View on GitHub (pinned to 693053b89a)
Solutions
- Ensure the JsonSerializer is constructed/resolved before calling Parse.
- If resolving from the dependency resolver, verify resolver.Resolve<JsonSerializer>() is non-null.
- Initialize the serializer field eagerly (e.g. in the constructor) rather than lazily without a null check.
Example fix
// before JsonSerializer _serializer; // never assigned var msg = _serializer.Parse<Message>(json); // throws ArgumentNullException // after _serializer = new JsonSerializer(); var msg = _serializer.Parse<Message>(json);
Defensive patterns
Strategy: validation
Validate before calling
if (serializer == null)
throw new InvalidOperationException("JsonSerializer was not initialized.");
var value = serializer.Parse<T>(json); Prevention
- Initialize JsonSerializer fields eagerly in the constructor.
- Resolve from the resolver and assert non-null at startup.
- Remember extension methods do not guard the receiver for you.
When it happens
Trigger: Calling serializer.Parse<T>(json) where the `serializer` variable is null. Because it is extension-method syntax, the null slips past the compiler.
Common situations: A resolver returning a null JsonSerializer; a service field that was never initialized; a JsonSerializer obtained via a factory that returned null under an error condition.
Related errors
- A client callback for event {0} with {1} argument(s) was fou
- convert
- name
- Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) d
- When calling ko.toJS, pass the object you want to convert.
AI-assisted analysis of SignalR/SignalR@693053b89a (2026-08-13).
Data as JSON: /api/errors/cd1229a9c4b1687a.
Report an issue: GitHub.