zhiyuan_
zhiyuan_

Reputation: 197

Type initializer for IBM.WMQ.MQQueueManager throws an exception

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!

Upvotes: 6

Views: 18334

Answers (3)

Stitch10925
Stitch10925

Reputation: 182

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.

Upvotes: 3

Herre Kuijpers
Herre Kuijpers

Reputation: 779

see also: .net using IBM MQ without full MQ client install

basically grab the 2 dlls from the WMQ bin folder: amqmdnet.dll & amqmdxcs.dll

I found for WMQ 7.5 you need to register the 2 dll's in the GAC for it to work correctly. you need admin persmissions to register them.

the reference the libraries in your project to use the native WMQ objects

Upvotes: 0

Shashi
Shashi

Reputation: 15263

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.

Upvotes: 5

Related Questions