azure-sdk-for-net: [BUG] EventGridEvent data set to anonymous object is not serialized properly

Describe the bug

When sending a message created using the following code:

new EventGridEvent()
{
	Id = Guid.NewGuid().ToString(),
	EventType = "namespace.events.ievent",
	Data = new
	{
		MessageTypes = "...",
	},

	EventTime = DateTime.Now,
	Subject = "subject-" + DateTime.Now.ToString(),
	DataVersion = "2.0"
};

The message arriving to the subscribers has empty data property ( data: {}).

Expected behavior

The message’s data property should contain serialized data.

Environment:

  • Name and version of the Library package used: Microsoft.Azure.EventGrid 3.2.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Data property is of type object which should be able to work with any type. If JObject is expected, that should be indicated in the documentation or the type would need to be explicit.

Assigning EventGridEvent.Data a JObject of your data object sounds like a leaking abstraction.

Looking at the tests along with the project it seems POCO objects are sent but never verified if the Data part is actually received. Also, it appears a custom event mapping has to be provided to deserialize custom events.

Perhaps @jfggdl and the team could provide more information or update the documentation? Thank you.

Anonymous types are supported in the new Azure.Message.EventGrid package that is currently in beta.

Project Readme - https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventgrid/Azure.Messaging.EventGrid/README.md

Thanks @SeanFeldman for reporting this issue. I am working on investigating/repro’ing the issue. We added this issue as a backlog item for current semester for proper prioritization and handling.

thanks