Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null reference bug in serializer #10

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
7 changes: 3 additions & 4 deletions src/Elmah.MongoDB/NameValueCollectionSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,17 @@ public override void Serialize(
IBsonSerializationOptions options
)
{
if (value == null)
var nvc = value as NameValueCollection;
if (nvc == null)
{
bsonWriter.WriteNull();
return;
}

var nvc = (NameValueCollection)value;

bsonWriter.WriteStartArray();
foreach (var key in nvc.AllKeys)
{
foreach (var val in nvc.GetValues(key))
foreach (var val in nvc.GetValues(key) ?? new string[0])
{
bsonWriter.WriteStartArray();
StringSerializer.Instance.Serialize(bsonWriter, typeof(string), key, options);
Expand Down