Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] New ServiceBusMessage Body empty if BinaryData created with FromObjectAsJson method #46006

Open
ivandamyanov opened this issue Sep 17, 2024 · 3 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus

Comments

@ivandamyanov
Copy link

ivandamyanov commented Sep 17, 2024

Library name and version

Azure.Messaging.ServiceBus 7.18.1

Describe the bug

I have a type called MyRequest with a public property TransactionId. I'm trying to create a ServiceBusMessage instance in the following way:
var message = new ServiceBusMessage(BinaryData.FromObjectAsJson(MyRequest)) { MessageId = messageId, Subject = "mySubject", };
After inspecting the message.Body property - it is empty even though TransactionId is already a valid Guid in the MyRequest instance passed to FromObjectAsJson.

As a workaround, I used Newtonsoft JsonConvert and UTF8.GetBytes like this and it works fine - the body is not empty:
var serializedMessageBody = Newtonsoft.Json.JsonConvert.SerializeObject(MyRequest); var bytes = Encoding.UTF8.GetBytes(serializedMessageBody); return new ServiceBusMessage(new BinaryData(bytes)) { MessageId = messageId, Subject = messageLabel };

Any idea what is the issue with BinaryData not filling in the Body property properly depending on the serializer? By the way, this seems to depend on the class being serialized because in another piece of code I have with AnotherRequest, FromObjectAsJson is used and then the Body is filled correctly.

Expected behavior

The Body should be filled in both cases

Actual behavior

The Body of ServiceBusMessage is empty

Reproduction Steps

I think using classes like the ones explained below will allow a reproduction of the issue:

The different between this piece of code with AnotherRequest and the one above with MyRequest is that:

AnotherRequest has these attributes (and it works with FromObjectAsJson):
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://example.namespace")]

and the public properties have:
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]

while the MyRequest class has these

[System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] [System.ServiceModel.MessageContractAttribute(WrapperName="OnConfirmationRequest", WrapperNamespace="http://example.namespace", IsWrapped=true)]
and the properties:

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://SecureApp/2017/SecureAppResponse", Order=0)]

Environment

Hosting in a ServiceFabric cluster on a Windows OS. The code is in a .NET 6 project.

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus labels Sep 17, 2024
Copy link

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@jsquire jsquire assigned jsquire and unassigned JoshLove-msft Sep 17, 2024
@jsquire
Copy link
Member

jsquire commented Sep 17, 2024

Hi @ivandamyanov. Thanks for reaching out and we regret that you're experiencing difficulties. Service Bus does not inspect nor alter the bytes passed to it for the body. If you're not seeing the body populated when using BinaryData but are when using Newtonsoft, it seems likely there's something in your structure that System.Text.Json handles differently than Newtonsoft.

Unfortunately, there's not enough context to speculate further. Can you share a small, stand-alone sample that reproduces the behavior that you're asking about?

@jsquire jsquire added needs-author-feedback Workflow: More information is needed from author to address the issue. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Sep 17, 2024
Copy link

Hi @ivandamyanov. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Projects
None yet
Development

No branches or pull requests

3 participants