Geoab
Geoab

Reputation: 75

MQQueueManager constructor fails when adding USER_ID_PROPERTY to Hashtable

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.

Upvotes: 3

Views: 1153

Answers (2)

JasonE
JasonE

Reputation: 2026

This is a product defect (I've also raised it as such). Basically if you provide a userid you MUST provide a password as the code dereferences the password field without first checking it is supplied... Sorry!

Upvotes: 4

Roger
Roger

Reputation: 7476

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.

Upvotes: 0

Related Questions