unoplatform/uno · error · ArgumentNullException

value

Error message

value

What it means

ArgumentNullException thrown by the implicit conversion operator from JsonValue to Guid when the passed JsonValue is null. System.Json (vendored in Uno.UI.Lottie) defines implicit operators for many CLR types; each guards against a null JsonValue by throwing ArgumentNullException(nameof(value)).

Source

Thrown at src/AddIns/Uno.UI.Lottie/System.Json/JsonValue.cs:520

			return (DateTimeOffset)((JsonPrimitive)value).Value;
		}

		public static implicit operator TimeSpan(JsonValue value)
		{
			if (value == null)
			{
				throw new ArgumentNullException(nameof(value));
			}

			return (TimeSpan)((JsonPrimitive)value).Value;
		}

		public static implicit operator Guid(JsonValue value)
		{
			if (value == null)
			{
				throw new ArgumentNullException(nameof(value));
			}

			return (Guid)((JsonPrimitive)value).Value;
		}

		public static implicit operator Uri(JsonValue value)
		{
			if (value == null)
			{
				throw new ArgumentNullException(nameof(value));
			}

			return (Uri)((JsonPrimitive)value).Value;
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Null-check the JsonValue before implicit conversion: if (node is JsonPrimitive prim) guid = prim;
  2. Use JsonObject.TryGetValue / ContainsKey to verify the key exists before access.
  3. Use explicit (Guid?) handling or JsonValue.Parse-based deserialization that respects optional fields.
  4. Validate the JSON schema includes the expected Guid field before conversion.

Example fix

// before
Guid id = obj["id"]; // throws if obj["id"] is null

// after
Guid id = obj["id"] is JsonValue v ? (Guid)v : Guid.Empty;
Defensive patterns

Strategy: type-guard

Validate before calling

// Check the node exists and is a primitive before Guid conversion
if (obj.TryGetValue("id", out var idNode) && idNode is JsonValue)
    guid = (Guid)idNode;
else
    guid = Guid.Empty;

Type guard

bool IsConvertibleToGuid(JsonValue? v)
    => v is JsonPrimitive p && p.JsonType == JsonType.String && Guid.TryParse((string)p.Value, out _);

Prevention

When it happens

Trigger: Casting/null-coercing a JsonValue to Guid via the implicit operator, e.g. Guid g = someJsonValueNode; where the node is null — common when a JSON property is missing and the lookup returned null and was directly assigned.

Common situations: Indexing into a JsonObject with a key that doesn't exist (returns null) and implicitly converting to Guid; deserializing a schema where a Guid field is optional but the code assumes presence.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/c488cdb78011b3ee. Report an issue: GitHub.