LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

[BUG] Calling `.ToString()` on a `BsonValue` constructed from a `string[]` throws a `NullReferenceException`

Open Cryptoc1 opened this issue 1 year ago • 1 comments

Version v5.0.21, on net9.0

Describe the bug When constructing a BsonValue from an array of strings, calling .ToString() throws a NullReferenceException.

Code to Reproduce

var tags = ["hello", "world"];

var value = new BsonValue(tags);

// THROWS!
value.ToString();

Expected behavior .ToString() should return the string representation of the array.

Screenshots/Stacktrace

An exception of type 'System.NullReferenceException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Object reference not set to an instance of an object.'
at LiteDB.JsonWriter.WriteArray(BsonArray arr)
at LiteDB.JsonWriter.WriteValue(BsonValue value)
at LiteDB.JsonSerializer.Serialize(BsonValue value, StringBuilder sb, Boolean indent)
at LiteDB.BsonValue.ToString()

...
<private code excluded>

Cryptoc1 avatar Feb 19 '25 05:02 Cryptoc1

Hello! Thank you for bringing this up! What is the string representation you would expect here?

JKamsker avatar Feb 19 '25 10:02 JKamsker