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

Hi I have a error when I try to create instance of MQQueueManager. The line 63 (from error) is create instance MQQueueManager.

The queue is configured on machine where I can not login and I don't know that the queue is running.

Is the error can deduce the cause of the failure?

System.TypeInitializationException: The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
   --- End of inner exception stack trace ---
   at IBM.WMQ.MQCommonServices..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at IBM.WMQ.CommonServices.CreateCommonServices()
   at IBM.WMQ.CommonServices.TraceEnabled()
   at IBM.WMQ.MQBase..ctor()
   at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
   at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
   at IBM.WMQ.MQQueueManager..cctor()
   --- End of inner exception stack trace ---
   at IBM.WMQ.MQQueueManager..ctor(String queueManagerName)
   at Ccap.Bnp.MQAdapter..ctor() in D:\Programowanie\Xxx\MQAdapter.cs:line 63
                What is the MQ version used (both client and server)?  Can you show the code where this exception is thrown
– Umapathy
                Sep 17, 2015 at 17:37
                I was tempted to roll back the last edit since the title originally said this is MQ v7.5.  However, Umpathy is correct that to get an informed answer requires explicitly stating versions for both client and server.  In fact, go to the websphere-mq tag wiki for guidance on what information to provide to improve the answers you are likely to get back.  Even with a low reputation, you can always edit your own question to add the requested info.
– T.Rob
                Sep 18, 2015 at 3:56
                Only information that i have it's MQ 7.5. Is it impossible deduce the cause of the failure from this error log?
– malymakar
                Sep 18, 2015 at 6:43
                System.TypeInitializationException is thrown by .net.  It could be the MQ connectionfactory/constructor is not properly initialized.  If you cant paste the source, suggest going through the .net manual and see what you have done wrong.  www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/…  .net sample www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/…
– Umapathy
                Sep 18, 2015 at 11:36

You are passing just the queue manager name to the MQQueueManager constructor. Have you initialized MQEnvironment? You need to initialize MQEnvironment when using a MQQueueManager constructor that takes only the queue manager as parameter. The other way is to pass a Hashtable containing host, port and channel properties to MQQueueManager constructor to establish a connection to a queue manager running on a different machine. If you have not initialized MQEnvironment or not using a Hashtable to pass host, port and channel properties, then the MQ.NET client will attempt to connect to a queue manager running on the same machine as your application.

Also do you have MQ Client installed on the machine where you run your application? You may be attempting to run your application with just AMQMDNET.DLL copied. This is one of the possible cause for System.TypeInitializationException exception. The AMQMDNET.DLL has dependency on other assemblies and native libraries.

I can update my answer based on your response.

Update You need MQ Client installed to run your application. Without the MQ Client your application will not work. Download and install MQ Client from here

I initialized MQEnvironment (host, port, channel). I don't have MQ Client installed on the machine where I run my application. In my project I have copied AMQMDNET.NET from Internet. – malymakar Sep 21, 2015 at 6:35

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.