aliencube/CloudEvents.NET

Data assign before ContentType throws NullReferenceException

Closed this issue · 2 comments

When an event object is directly created, instead of using CloudEventFactory, if Data is assigned first than ContentType, it throws the NullReferenceException error.

// This throws an exception
var ev = new ObjectEvent()
{
    Data = new { Hello = "World" },
    ContentType = "application/json"
};

However, if ContentType is defined first, followed by Data, it's OK.

// This is fine
var ev = new ObjectEvent()
{
    ContentType = "application/json",
    Data = new { Hello = "World" }
};

The interim solution will be:

  1. Define ContentType first, then define Data, or
  2. Use CloudEventFactory to create an ObjectEvent, StringEvent or BinaryEvent.

Fixed and NuGet package v0.1.1 has been released