{"record":{"id":"d1162b08a32c5bed","repo":"clockworklabs/SpacetimeDB","slug":"cannot-serialize-a-null-string-as-bsatn-string-to","errorCode":null,"errorMessage":"Cannot serialize a null string as BSATN String. To serialize a null string you must use a nullable string (string?) so it is encoded as a BSATN option.","messagePattern":"Cannot serialize a null string as BSATN String\\. To serialize a null string you must use a nullable string \\(string\\?\\) so it is encoded as a BSATN option\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs","lineNumber":560,"sourceCode":"        writer.Write(value.Length);\n        writer.Write(value);\n    }\n\n    public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>\n        new AlgebraicType.Array(new AlgebraicType.U8(default));\n}\n\n// String is a special case of byte array with extra checks.\npublic readonly struct String : IReadWrite<string>\n{\n    public string Read(BinaryReader reader) =>\n        Encoding.UTF8.GetString(ByteArray.Instance.Read(reader));\n\n    public void Write(BinaryWriter writer, string value)\n    {\n        if (value is null)\n        {\n            throw new ArgumentNullException(\n                nameof(value),\n                \"Cannot serialize a null string as BSATN String. To serialize a null string you must use a nullable string (string?) so it is encoded as a BSATN option.\"\n            );\n        }\n\n        ByteArray.Instance.Write(writer, Encoding.UTF8.GetBytes(value));\n    }\n\n    public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>\n        new AlgebraicType.String(default);\n}\n\npublic readonly struct List<Element, ElementRW> : IReadWrite<List<Element>>\n    where ElementRW : IReadWrite<Element>, new()\n{\n    private static readonly Enumerable<Element, ElementRW> enumerable = new();\n    private static readonly ElementRW elementRW = new();\n","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs#L542-L578","documentation":"Error \"Cannot serialize a null string as BSATN String. To serialize a null string you must use a nullable string (string?) so it is encoded as a BSATN option.\" thrown in clockworklabs/SpacetimeDB.","triggerScenarios":"Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs:560 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}