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.

[Feature Request] Deserialize message sent from WindowsAzure.ServiceBus (Track Zero)

See original GitHub issue

We might want to add an API, sample, or document explaining how to deserialize a message sent from WindowsAzure.ServiceBus (the “Track 0” SDK). To run the following repro, create a .NET Framework console app (not .NET Core) and add package references to WindowsAzure.ServiceBus (Track 0) and Azure.Messaging.ServiceBus (Track 2).

// Send from WindowsAzure.ServiceBus (Track 0)
var factory1 = MessagingFactory.CreateFromConnectionString(connectionString);
var client1 = factory1.CreateQueueClient("test");
client1.Send(new BrokeredMessage("WindowsAzure.ServiceBus"));

// Receive from Azure.Messaging.ServiceBus (Track 2)
var client2 = new ServiceBusClient(connectionString);
var receiver2 = client2.GetReceiver("test");
var message2 = await receiver2.ReceiveAsync();

var body2Bytes = message2.Body.ToArray();

var invalidBody2 = Encoding.UTF8.GetString(body2Bytes);
Console.WriteLine(invalidBody2);
// @strin3http://schemas.microsoft.com/2003/10/Serialization/?WindowsAzure.ServiceBus

var validBody2 = Deserialize<string>(body2Bytes);
Console.WriteLine(validBody2);
// WindowsAzure.ServiceBus

await receiver2.CompleteAsync(message2);

public static T Deserialize<T>(byte[] data)
{
    var serializer = new DataContractSerializer(typeof(T));
    using (var stream = new MemoryStream(data))
    using (var reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max))
    {
        return (T)serializer.ReadObject(reader);
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jsquirecommented, Mar 23, 2020

For more context, it appears that this issue exists in the track one library as well, where it is worked around by use of two types in the Extensions namespace, one of which provides a special serializer and the other which offers an extension method to the message object. These can be seen in the following locations:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure service bus Message deserialize broken in core ...
1 Answer. Message. GetBody<T>() is an extension method for messages sent using the legacy Service Bus SDK (WindowsAzure. ServiceBus package) ...
Read more >
Track custom operations with Application Insights .NET SDK
Application Insights SDKs automatically track incoming HTTP requests and calls to dependent services, such as HTTP requests and SQL queries.
Read more >
Azure service bus SerializationException due to extra bytes
I'm getting a SerializationException when the consumer tries to deserialize the message envelope: SerializationException: An exception occurred while ...
Read more >
Azure ServiceBus Message Serialization/Deserialization
Assume the following class is the type of which object instances will be sent to/received from an Azure Service Bus queue:
Read more >
Using Windows Azure Service Bus Messaging.
This article describes consuming Windows Azure Service Bus by WCF and WF Technologies.
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