title: MQ putting messages C#
body: <p>I am busy with <code>C# MQ</code>, i want to add text on the Q, but not sure if what i am doing is wrong. Getting the following error.</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.NullReferenceException'
    occurred in Data.Manager.dll, this happens at
    "Put1Queue.Put(myPutMessage, Put1PutMsgOptions);"</p>
  </blockquote>
  
  <p>Here is the code:</p>
  
  <pre><code>class Program
  {
  
      static void Main(string[] args)
      {
          MQ mq = new MQ();
          Console.Read();
      }
  }
  
  public class MQ
  {
  
      private MQQueue queue;
      private MQMessage queueMessage;
      private MQQueueManager queueManager;
  
      private string queueManagerName;
      private string host;
      private int port;
      private string channel;
      private string queueName;
  
      public String putMsg;
      public String markerMsg;
      private MQQueueManager Put1QueueManager;
      private MQPutMessageOptions Put1PutMsgOptions;
      private MQQueue Put1Queue;
  
      private MQQueueManager Put2QueueManager;
      private MQPutMessageOptions Put2PutMsgOptions;
      private MQQueue Put2Queue;
  
      private MQQueueManager myQueueManager;
      private MQPutMessageOptions myPutMsgOptions;
      private MQQueue myQueue;
  
      private Hashtable queueProperties;
  
      public MQ()
      {
          setupTestData();
  
      }
  
      public void setupTestData()
      {
  
          markerMsg = "&lt;msglamdav5_xml&gt;&lt;system message_id=\"\" message_type=\"\" correlation_id=\"\" date_time_stamp=\"\" originator=\"\" destination=\"\" queue_manager=\"\" txn_req_number=\"\" txn_req_id=\"\"/&gt;&lt;security user_name=\"G9022O2 \" user_type=\"\" user_identity=\"G90226K     \" user_language=\"\" environment=\"PPEX    \" host_name=\"\"/&gt;&lt;errors/&gt;&lt;data&gt;&lt;txn_ctl bus_txn_phase=\"3\" bus_txn_session_id=\"\" /&gt;&lt;data_key party_no=\"0\"/&gt;&lt;tasks&gt;&lt;task txn_id=\"MARK&lt;uniqueNum&gt; \" event_type=\"2\" external_txn_id=\"04255841252012-06-22-04.56.14.960000            \"&gt;&lt;task_data&gt;&lt;servicedata inputdata=\"0124473471\"/&gt;&lt;/task_data&gt;&lt;task_metadata&gt;&lt;lists/&gt;&lt;/task_metadata&gt;&lt;/task&gt;&lt;/tasks&gt;&lt;/data&gt;&lt;/msglamdav5_xml&gt;";
  
          try { 
          // Setup connection information
          MQEnvironment.Hostname = "SLHUBQ2.sanlam.co.za";
          MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
          MQEnvironment.properties.Add(MQC.CCSID_PROPERTY, 437);
          MQEnvironment.Channel = "CLIENTS";//"EFL.SRVCONN";
          MQEnvironment.Port = 1615;//lr.eval_int("&lt;Port&gt;");
  
  
          Put1QueueManager = new MQQueueManager("SLHUBQ2");
          int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
  
          Put1Queue = Put1QueueManager.AccessQueue("LAMDA.PERF.REQUEST", openOptions, null, null, null);
  
          Put1PutMsgOptions = new MQPutMessageOptions();
  
          Put1PutMsgOptions.Options = MQC.MQPMO_NEW_MSG_ID | MQC.MQPMO_NEW_CORREL_ID;
  
          }
          catch (Exception error)
          {
  
          }
  
          try {
                  MQMessage myPutMessage = new MQMessage();
                  myPutMessage.ClearMessage();
                  myPutMessage.Persistence = MQC.MQPER_PERSISTENT;
                  myPutMessage.Persistence = MQC.MQPER_NOT_PERSISTENT;
                  myPutMessage.CorrelationId = MQC.MQCI_NONE;
                  myPutMessage.MessageId  = MQC.MQMI_NONE;
  
                  myPutMessage.Format = MQC.MQFMT_STRING; 
                  myPutMessage.ReplyToQueueName= "LAMDA.PERF.RESPONSE";
  
                  myPutMessage.WriteString(markerMsg);
  
  
                Put1Queue.Put(myPutMessage, Put1PutMsgOptions);
  
  
  
  
          }
          catch (MQException error)
          {
  
  
          }
  
  
          try
          {
              Put1Queue.Close();
              Put1QueueManager.Disconnect();
  
          }
          catch (Exception error)
          {
  
          }
  
  
  
      }
  
  
  
      }
  }
  </code></pre>