{"record":{"id":"fcc1502be73aa8af","repo":"dotnetcore/CAP","slug":"type-is-not-of-type-jsonelement","errorCode":null,"errorMessage":"Type is not of type JsonElement","messagePattern":"Type is not of type JsonElement","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP/Serialization/ISerializer.JsonUtf8.cs","lineNumber":56,"sourceCode":"\n        return new ValueTask<Message>(new Message(transportMessage.Headers, obj));\n    }\n\n    public string Serialize(Message message)\n    {\n        return JsonSerializer.Serialize(message, _jsonSerializerOptions);\n    }\n\n    public Message? Deserialize(string json)\n    {\n        return JsonSerializer.Deserialize<Message>(json, _jsonSerializerOptions);\n    }\n\n    public object? Deserialize(object value, Type valueType)\n    {\n        if (value is JsonElement jsonElement) return jsonElement.Deserialize(valueType, _jsonSerializerOptions);\n\n        throw new NotSupportedException(\"Type is not of type JsonElement\");\n    }\n\n    public bool IsJsonType(object jsonObject)\n    {\n        return jsonObject is JsonElement;\n    }\n}","sourceCodeStart":38,"sourceCodeEnd":63,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP/Serialization/ISerializer.JsonUtf8.cs#L38-L63","documentation":"A type guard in the JsonUtf8 serializer's Deserialize(object value, Type valueType) overload: this implementation can only rehydrate values that arrived as System.Text.Json JsonElement nodes (the shape produced when CAP deserializes the message body with JsonUtf8). Passing a string, byte[], JObject, or any other runtime type reaches the guard and fails with NotSupportedException; the faulty input is the boxed 'value' argument, not the target valueType.","triggerScenarios":"Thrown at src/DotNetCore.CAP/Serialization/ISerializer.JsonUtf8.cs:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the input to a JsonElement first (e.g. parse a JSON string with JsonSerializer.Deserialize<JsonElement>(json)) before calling this overload.","If you need to deserialize from string or bytes, call the string-based Deserialize(json) overload instead.","When substituting serializers in CAP options, ensure producer and consumer both use the same serializer so bodies arrive as JsonElement.","Use a custom ISerializer implementation matching your wire format (registered in AddCAP) instead of relying on JsonUtf8Serializer for non-JsonElement inputs."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}