Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Basically, I was given a task at work that involves using IBM MQ and C#, and while I am good with C#, I am a total newbie when it comes to Network programming and IBM MQ (As in I barely started using IBM MQ yesterday).

Anyway, after reading through a lot of guides, and examples, and troubleshooting a lot of stuff I managed to make a C# solution that connects to a QueueManager, and successfully sends and reads messages. However, I only managed to do so by disabling the default Authorisation, and while that was good when all I needed to do was test my Adapter class, I now need to be able to specify an User Id and a Password, and eventually restore all the Authorisation settings I disabled.

Here is the problem though, whenever I try to add the USER_ID_PROPERTY property to the connectionProperties Hashtable the QMQueueManager constructor returns a Null reference System Exception.

Here is the code where I build the Hashtable;

Hashtable connectionProperties = new Hashtable();
        // Add the connection type
        connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
        // Set up the rest of the connection properties, based on the   connection type requested
        switch (connectionType)  {
            case MQC.TRANSPORT_MQSERIES_BINDINGS: break;
            case MQC.TRANSPORT_MQSERIES_CLIENT:
            case MQC.TRANSPORT_MQSERIES_XACLIENT:
            case MQC.TRANSPORT_MQSERIES_MANAGED:
                //connectionProperties.Add(MQC.USER_ID_PROPERTY, "newUser");
                connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
                connectionProperties.Add(MQC.PORT_PROPERTY, 1421);
                connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                connectionProperties.Add(MQC.CONNECTION_NAME_PROPERTY, connectionName);
                break;
            default:
                Console.WriteLine(connectionType + " is not a valid connection type");
                break;
        return connectionProperties;

If I run the code as is, everything works out fine, I get connected to the Queue, send, read, and disconnect without an issue, the moment I uncomment the Use ID line, I get a Null Reference System Exception on the following line;

qmQueueManager =  new MQQueueManager(qManager, connectionProperties); 

This is the exception message that pops up:

A System error occurred: System.NullReferenceException: Object reference not set to object instance. At IBM.WMQ.MQQueueManager.Connect (String queueManagerName) At IBM.WMQ.MQQueueManager..ctor (String queueManagerName, Hashtable properties) At MQNetworkClient.MQManager.ConnectMQ (String details) Location C: \ Users \ A440 \ Documents \ Visual Studio 2017 \ Projects \ MQNetworkClient \ MQNetworkClient \ MQManager.cs: Line 124 At MQNetworkClient.MQManager.TryMQAction (MQSanityCheck sanityCheck, MQActionHandler mqAction, String details, String sanityFailMessage) Location C: \ Users \ A440 \ Documents \ Visual Studio 2017 \ Projects \ MQNetworkClient \ MQNetworkClient \ MQManager.cs: Line 95

The error message doesn't give me much to go on, and while I checked the QueueManager's AMQError Logs but nothing gets written there.

I would really appreciate any solution, work-around, or any help tracing the issue, basically, I would grateful to get any kind of advice that could potentially point me towards the right direction here.

In case it is somehow relevant, I am using IBM MQ v9, and Visual Studio 2017.

Thank you.

If you specify a value for the User ID property, you must also specify a value for the Password property. – Hans Passant Sep 14, 2017 at 17:16 Thank you! I can't believe it was something as simple as that, adding the Password property fixed the issue. Again, thank you. – Geoab Sep 15, 2017 at 5:23 Please accept JasonE's answer as it appears this is a product defect that will be fixed in a future fixpack, in the mean time a work around as suggested by Hans Passant will allow it to work now. To accept just click the grayed out check mark to the left of the answer below the down arrow. – JoshMc Sep 19, 2017 at 5:41 Internal defect, although if you need an APAR contact IBM support. Given the simple workaround, it shouldnt really be a problem to avoid. Note I suspect if you just provided password and not userid you might see the same too – JasonE Sep 16, 2017 at 19:41 Thank you for the info. The APARs are helpful in that they provide a good reference if you are seeing a problem and are not at the latest version. 1. it will tell you in which fixpack it is corrected, 2. a local work around until you get to that level. This SO question will provide #2. – JoshMc Sep 16, 2017 at 21:08

I think you have a different issue. I set the UserId and Password as a Hashtable property all the time in C# .NET without any problems. See my post HERE.

Try a different/lower .NET framework version. i.e. You may be using one that is not supported by IBM.

Hans Passant's comment actually solved the issue, but thank you for providing me a link to your post since it will definitely be useful anyway. – Geoab Sep 15, 2017 at 5:27

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.