[BUG] Azure.Messaging.EventGrid SDK does not parse KeyVault system event data types correctly due to case mismatch
See original GitHub issueDescribe the bug
I’ve been trying to work with some KeyVault events, and have found that using the new Azure.Messaging.EventGrid
SDK to read the events produces blank objects. The object instance is the correct type, but all properties are null. As best as I can tell, this is because the delivered events use a different casing than the SDK expects. For instance, here is a (slightly cleaned up) event instance:
{
"id": "39869b5c-6d56-404b-aab8-50ec200f93f8",
"topic": "/subscriptions/***/resourceGroups/sample-rg/providers/Microsoft.KeyVault/vaults/sample-vault",
"subject": "TestSecret",
"eventType": "Microsoft.KeyVault.SecretNewVersionCreated",
"data": {
"Id": "https://sample-vault.vault.azure.net/secrets/TestSecret/a9f4eab27ec64771ac1fb07d38fdbae2",
"VaultName": "sample-vault",
"ObjectType": "Secret",
"ObjectName": "TestSecret",
"Version": "a9f4eab27ec64771ac1fb07d38fdbae2",
"NBF": 1627491993,
"EXP": 1690563970
},
"dataVersion": "1",
"metadataVersion": "1",
"eventTime": "2021-07-28T17:08:38.2145376Z"
}
The casing on the data properties is title-cased (documented as such here), but the SDK expects camel-casing (as code-generated here). The Microsoft.Azure.EventGrid
SDK appears to have used this incorrect casing too (here), but it still produced working event data instances since NSJ fuzzy-matched on the property keys. I can get the object to parse correctly if I modify the payload to have the expected casing, but that’s not something I’d want to deploy.
There may be other event data structures beyond KeyVault types that have this inconsistency as well, but I haven’t looked too closely. For now, I’m moving back to the previous-generation SDK so that I can be unblocked here, but this seems like a pretty glaring bug in the new SDK. Hopefully I can update back to it at some point. 😄
Expected behavior
Azure.Messaging.EventGrid
parses KeyVault SecretNewVersion (and other) event data structures correctly.
Actual behavior (include Exception or Stack Trace) An instance of the correct type is provided, but it has all null values.
To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)
- Create a Key Vault.
- Register an event subscription for New Secret Version events.
- Parse the provided payload with Azure.Messaging.EventGrid.
Environment:
- Name and version of the Library package used: Azure.Messaging.EventGrid 4.5.0
- Hosting platform or OS and .NET runtime version (
dotnet --info
output for .NET Core projects): .NET Core 3.1 and 5.0 - IDE and version : Visual Studio 16.10.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Thanks, #23208 / v4.6.0 works!
This is fixed in 4.6.0 - https://www.nuget.org/packages/Azure.Messaging.EventGrid/4.6.0