title: From C# after getting IBM MQ message how to identify message data type? Is it Object or String type?
body: <p>In our company we are using IBM MQ server for message queueing. For the same queue we are putting both String and Object type data message with the help of methods WriteObject and WriteString.</p>
  
  <p>The challenge is occured when it comes to consumption(read message) of queue. Since the Get data can be both Object or String we need to decide which method to use ReadString or ReadObject on the MQMessage instance. I made workaround like firstly using ReadObject method, if an exception occured then try it with ReadString.</p>
  
  <p><strong>I did not like this workaround, is there any way to identify message data type after calling MQQueue instance's Get method?</strong></p>
  
  <p>Here below you can find my workaround:</p>
  
  <pre><code>    public object GetMessage(string queueName) {
  
          MQQueueManager queueManager = new MQQueueManager("queueManagerName", "channel", "connection");
          MQGetMessageOptions queueGetMessageOptions = new MQGetMessageOptions();
          queueGetMessageOptions.Options = MQC.MQGMO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQPMO_SYNCPOINT;
  
          try {
              queueRead = queueManager.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
              queueMessage = new MQMessage();
              queueMessage.Format = MQC.MQFMT_STRING;
              queueRead.Get(queueMessage, queueGetMessageOptions);
  
              try {
                  var readObject = queueMessage.ReadObject();
                  return readObject;
              } catch (SerializationException) { } // if message in queue not a object
  
              queueMessage.DataOffset = 0;
              var stringMsg = queueMessage.ReadString(queueMessage.MessageLength);
              return stringMsg;
  
          } catch (MQException exp) {                
              if (exp.ReasonCode != 2033) {
                  log.ErrorFormat("MQException: ResonCode: {0}, {1}", exp.ReasonCode, exp.Message);                    
              }
          }
          return "";
      }
  </code></pre>