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

DataContract Serialized Stream-Bodied Messages Sent in Repair and Submit Are Corrupted #245

Closed
c-lombardi opened this issue Aug 20, 2018 · 5 comments
Labels

Comments

@c-lombardi
Copy link
Contributor

When re-queuing Dead-Letter-Queued messages with a Stream body that have a custom content type that was serialized by a Data-Contract-Serializer, the stream sent in the new message can no longer be read by the application that originally Data-Contract-Serialized the message.

Attempting to re-queue the same messages with ByteArray and String content types are also unsuccessfully able to be de-serialized by the application.

It appears that the message body is corrupted when the body was a custom content type and serialized with the DataContractSerializer.

@c-lombardi
Copy link
Contributor Author

c-lombardi commented Aug 20, 2018

I think that you might just need to instantiate the new BrokeredMessage with the body of the old message as a stream:

BrokeredMessage newBrokeredMessage = new BrokeredMessage(deadLetteredMessage.GetBody<Stream>()) { SessionId = deadLetteredMessage.SessionId, ContentType = deadLetteredMessage.ContentType, CorrelationId = deadLetteredMessage.CorrelationId, ForcePersistence = deadLetteredMessage.ForcePersistence, Label = deadLetteredMessage.Label, MessageId = deadLetteredMessage.MessageId, PartitionKey = deadLetteredMessage.PartitionKey, ReplyTo = deadLetteredMessage.ReplyTo, ReplyToSessionId = deadLetteredMessage.ReplyToSessionId, ScheduledEnqueueTimeUtc = deadLetteredMessage.ScheduledEnqueueTimeUtc, TimeToLive = deadLetteredMessage.TimeToLive, To = deadLetteredMessage.To, ViaPartitionKey = deadLetteredMessage.ViaPartitionKey };

@paolosalvatori
Copy link
Owner

paolosalvatori commented Aug 21, 2018

Hi @c-lombardi the Clone overloaded method in the BrokeredMessageExtensions class should do exactly what you are looking for. This is the first time that I receive this feedback. Could you please debug the application and see if the proper method overload is used when choosing Stream as format for the message to resubmit?

        public static BrokeredMessage Clone(this BrokeredMessage message, Stream stream)
        {
            if (stream == null)
            {
                return null;
            }
            if (stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }
            var clone = message.Clone();
            BodyStreamPropertyInfo.SetValue(clone, stream);
            return clone;
        }

@c-lombardi
Copy link
Contributor Author

I see what you are saying now and that seems to have resolved the problem for me in my local build!

@SeanFeldman
Copy link
Collaborator

seems to have resolved the problem for me in my local build!

Just making sure you're always using the latest release that can be obtained here.

@stale
Copy link

stale bot commented Nov 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 13, 2020
@stale stale bot closed this as completed Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants