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

Created on 21 May 2020  路  18Comments  路  Source: Azure/azure-sdk-for-net

Describe the bug

When sending a message created using the following code:

```c#
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
Client Event Grid Service Attention customer-reported needs-team-attention question

Most helpful comment

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.

All 18 comments

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jfggdl.

//fyi: @ellismg

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

@SeanFeldman can you please confirm what is the type of destination you are using here ? storage queue? Function? etc?

@ahamad-MS Queue Storage was my events handler/destination.

@SeanFeldman Thanks.. We suspect that this issue from storage queue itself. Will you be able to use another destination type to confirm?

@ahamad-MS, same happens with Service Bus handler.
I am not convinced this is a downstream service issue. They get what they are passed. So whatever is being sent is wrong.

@ahamad-MS any updates?

Having a similar issue, our data property is empty for a 'normal' object.
Tried passing a string and JObject, both result in a filled data property, only to be a double-escaped string which is also wrong.

@ahamad-MS, any updates?

Turns out I made a mistake and did not actually try passing a JObject on the EvetGridEvent's data property. Passing the JObject made it so that my (complex, normal) object serialized correctly and as expected.

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.

@jfggdl, here's the code I've used to reproduce the issue.

```c#
async Task Main()
{
var topicEndpoint = "";
var topicKey = "
";
var topicHostname = new Uri(topicEndpoint).Host;

TopicCredentials topicCredentials = new TopicCredentials(topicKey);
EventGridClient client = new EventGridClient(topicCredentials);

await client.PublishEventsAsync(topicHostname, GetEventsList());

Console.Write("Published events to Event Grid.");

}

static IList GetEventsList()
{
List eventsList = new List();
for (int i = 0; i < 1; i++)
{
eventsList.Add(new EventGridEvent()
{
Id = Guid.NewGuid().ToString(),
EventType = "BlogPostPublished",
Data = new // note that with "new CustomData" it does work
{
ItemUri = "https://weblogs.asp.net/sfeldman/eventgrid-events-with-nservicebus"
},

        EventTime = DateTime.Now,
        Subject = "Processing Azure Event Grid events with NServiceBus",
        DataVersion = "1.0"
    });
}
return eventsList;

}

public class CustomData
{
public string ItemUri;
}
```

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

@SeanFeldman Agreed. However, this workaround allows us to work with it for the time being.

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

@SeanFeldman @i3anaan ... Thanks for your patience on this issue while we are working through the new track of Data plane SDK. As @JoshLove-msft mentioned, this issue is fixed in the new package and we verified that. The new package is the way to go given it supports additional features (e.g., cloud events, etc) and fixes many other issues.

Please move on to the new package and let us know if you hit any issue.

Given that there is a workaround for this issue in old version and the issue does not repro in the new version, we request this issue being closed unless we are missing something.

thanks

Thank you @JoshLove-msft for the update.

@ahamad-MS The new package will become an option when it's out of preview. There are still organizations that treat preview packages as what they are - preview not intended for production 馃檪

I'll close the issue as there's not going to be fixed in v3 and v4 is hopefully soon out.

@SeanFeldman Thanks for the feedback. It is totally understandable how external customers feel about preview features/APIs and they are right in their view. However, it is unfortunate for us as we build these preview APIs/SDKs and publish them with highest quality in order to ensure we get developers/customers feedback and thoughts on them before we GA.

Thanks for closing the issue.

Was this page helpful?
0 / 5 - 0 ratings