MSMQ BinaryFormatter. Convert to String

Hi Guys,
I'm really struggling with this.  I need to be able to receive a message from a MSMQ and convert the message to a string.  The examples I've seen (from MS) all convert the message to a bitmap which is not gonna help me.  
Here's the beginning of the code

    Private Sub qQueueForReceiving_ReceiveCompleted(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Handles qQueueForReceiving.ReceiveCompleted
        Dim msgText As String
        Dim eMsg As Message
        'Get message from event arguments (e)
        eMsg = e.Message
        eMsg.Formatter = New BinaryMessageFormatter()
Any help is GREATLY appreciated
Who is Participating?
you can try something like that:
Dim eMsg As Messaging.Message
Dim Br As BinaryReader
Dim msgText As String

 m = eMsg.Receive(New TimeSpan(0, 0, 3))
 Br = New BinaryReader(m.BodyStream)
 msgText  = New String(Br.ReadChars(CInt(m.BodyStream.Length)))

Open in new window

check out these links:

You are sure that the message is encoded in binary style?
It is possible to store MSMQ in Xml format. That makes it easier to process the message and you can look at the content in the queue itself - makes bug tracing much easier.
wherewasiAuthor Commented:
Thanks.  Now I have another question.

I have legacy VB for some software that is not going to be upgraded to VB .Net any time soon.  I want to use (as the receiving application)  an MSMQ Receiver/Server that is written in VB .Net.  

The sending application seems to send a string.  If I decode using any of the Formatters available in .Net I get garbage (as with the ActiveXFormatter) or I get errors/exceptions. .  Is there a simple solution?

Thanks again,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.