ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ API SupportMQMessage.ReadString Unable to read beyond the end of stream

Post new topicReply to topic
MQMessage.ReadString Unable to read beyond the end of stream View previous topic :: View next topic
Author Message
ryanframes
PostPosted: Sun Mar 07, 2021 8:10 pm Post subject: MQMessage.ReadString Unable to read beyond the end of stream Reply with quote

Newbie

Joined: 07 Mar 2021
Posts: 1

Hello,
I have a c# program that read MQ Message, it works for almost 7 months. But now suddenly it throw error
"Unable to read beyond the end of the stream at System.IO.BinaryReader.ReadString() at IBM.WMQ.MQMessage.ReadString(Int32 length) at ....."

Here's my code snippet to read MQ Message
Code:

if (CountMessage(p_sQueue) > 0)
                {
                    oMQQueue = m_oMQQueueManager.AccessQueue(p_sQueue, IBM.WMQ.MQC.MQOO_INPUT_EXCLUSIVE | IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING);
                    if (oMQQueue == null)
                    {
                        m_sErrorMessage = "Get : MQQueue is null";
                        return false;
                    }

                    MQMessage oMQMessage = new MQMessage();
                    MQGetMessageOptions oMQGetMessageOptions = new MQGetMessageOptions();

                    oMQGetMessageOptions.Options = IBM.WMQ.MQC.MQGMO_WAIT;
                    oMQGetMessageOptions.WaitInterval = m_iTimeout * 1000;
                    oMQGetMessageOptions.MatchOptions = IBM.WMQ.MQC.MQMO_NONE;

                    oMQQueue.Get(oMQMessage, oMQGetMessageOptions);


                    //string strRqId = oMQMessage.GetStringProperty("usr_UUID");

                    //byte[] bty = null;
                    //oMQMessage.ReadFully(ref bty);
                    //p_sMessage = System.Text.Encoding.UTF8.GetString(bty);
                    p_sMessage = oMQMessage.ReadString(oMQMessage.MessageLength);
                    oMQMessage.ClearMessage();
                    oMQMessage = null;

                    oMQGetMessageOptions = null;
                    return true;
                }


I'm using version 8.0.0.7

What could be possibly the cause for it to happen ?

found some link that useful :
en*morzel*net/post/IBMWMQMQMessageReadString-and-EndOfStreamException

Quote:

The error was reported, because sometimes in two different locations there was a call to ReadString method on the same MQMessage object:


but i never call this method more than one time, and i create MQMessage as Local Variable !

Now , i want to replicate this bug in development environment but i dont know what to do ?
Any help / advice regarding this error will be appreciated.

Thank you.
Back to top
View user's profile Send private message
hughson
PostPosted: Sun Mar 07, 2021 10:04 pm Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1549
Location: Bay of Plenty, New Zealand

What is the value of oMQMessage.MessageLength when you get this error? Does this not simply imply that it is zero?

Where is the code to check whether you were actually returned a message on the oMQQueue.Get call.

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
bruce2359
PostPosted: Sun Mar 07, 2021 10:06 pm Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 8887
Location: US: west coast, almost. Otherwise, enroute.

So, it worked for 7 months and now it gets an error.

What has changed? Program Code? O/S? MQ?

If you say that nothing has changed, it is unlikely that we will believe you.

How is the data (in error) different from when the app worked?
_________________
Five out of four people have trouble with fractions. - Steven Wright.
Back to top
View user's profile Send private message
tczielke
PostPosted: Mon Mar 08, 2021 5:43 am Post subject: Reply with quote

Guardian

Joined: 08 Jul 2010
Posts: 912
Location: Illinois, USA

This issue reminds me of the scenario where the readString method hits an error because the number of chars and number of bytes do not coincide. In Java, we use code like this to account for this type of scenario.

Code:

         queue.get(rcvMessage, gmo);
         int length = rcvMessage.getDataLength();
         String msgText = rcvMessage.readStringOfByteLength(length);


Here is a blurb from the readString method for the MQMessage class:

Quote:

Parameters:
length - The number of characters to read (which might differ from the number of bytes according to the codeset, since some codesets use more than one byte per character).

_________________
Working with MQ since 2010.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 08, 2021 6:41 am Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20458
Location: LI,NY

Why are you trying to read a string when you haven't ascertained the format of the message to be a MQFMT_STRING?

You could have a binary content that includes a string terminator... Hence your error message?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ API SupportMQMessage.ReadString Unable to read beyond the end of stream
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.