question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] EventGridEvent data set to anonymous object is not serialized properly

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
SeanFeldmancommented, Sep 4, 2020

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.

1reaction
JoshLove-msftcommented, Oct 2, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Event Grid serialize my already serialized data?
If I deserialize without a type, it becomes an escaped string. I tried to read the data as JObject instead of EventGridEvent, but...
Read more >
Casting object to Anonymous Types in C# - Mitch Valenta
In my test, I wanted to validate the data on one of the models in that anonymous type that is set in IActionResult's...
Read more >
EventGridEvent Class (Azure.Messaging.EventGrid)
Gets or sets the event payload as BinaryData. Using BinaryData, one can deserialize the payload into rich data, or access the raw JSON...
Read more >
Serialized anonymous classes using JsonUtility
I tried today to serialize an anonymous type, and it returns me an empty json object. It would be nice to be able...
Read more >
Deserialize an Anonymous Type
This sample deserializes JSON into an anonymous type. ... Serialize a DataSet · Serialize Raw JSON value · Serialize Unindented JSON.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found