Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type initializer for IBM.WMQ.MQQueueManager throws an exception

Tags:

ibm-mq

When I connect WebSphere MQ using C# without installing MQ server and client, I get the exception The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception. I add the reference of two MQ dlls, amqmdnet.dll and amqmdxcs.dll from MQ server, but it doesn't work. How can I connect to MQ without installing MQ server or client? Thank you!

like image 313
zhiyuan_ Avatar asked Apr 18 '12 06:04

zhiyuan_


2 Answers

I don't recommend using MQ client libraries without installing them. Installation ensures that all the required binaries are installed and registered with GAC. Adding reference to amqmdxcs is not required. Just a reference to amqmdnet is enough.

So it's better to install MQ client and run your application.

like image 169
Shashi Avatar answered Oct 23 '22 06:10

Shashi


Yes you can, you will need the following 2 DLL's: "amqmdnet.dll" and "amqmdxcs.dll"

You can then either:

  1. Register these 2 DLL's in the Global Assembly Cache (GAC)
  2. You can just add them as references to your project

Note, however: For option 2 you need to make sure that the registry path "HKEY_LOCAL_MACHINE\SOFTWARE\IBM\WebSphere MQ\Installation" exists.

If it does not exist and the DLL's are not in the GAC you will get the following exceptions:

System.TypeInitializationException: The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception. --> System.TypeInitializationException: The type initializer for 'IBM.WMQ.CommonServices' threw an exception. --> System.NullReferenceException: Object reference not set to an instance of an object.

This is because, when not in the GAC, the 'amqmdxcs.dll' which contains the 'IBM.WMQ.CommonServices' will try to read the sub-keys from the registry path to fill up some variables, but since it does not exist, it will fail.

For me, this approach works without needing any values in the "Installation" key.

like image 3
Stitch10925 Avatar answered Oct 23 '22 05:10

Stitch10925