|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' |
« View previous topic :: View next topic » |
Author |
Message
|
pelife |
Posted: Fri Mar 16, 2012 9:37 am Post subject: The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
Hello folks, I am having a bit of a problem trying to get started with Websphere MQ v7.1.
I downloaded and installed the Websphere MQ Server on my computer and I was hoping to get stated in developing .NET applications enabled to communicate through queues.
Installing the server I selected custom installation and selected the client components as well.
In my applications, I referenced the amqmdnet.dll and wrote the following code:
Code: |
static void Main(string[] args)
{
// Setup some test data
string queueManagerName = "QM_ORANGE";
string host = "127.0.0.1";
int port = 1415;
string channel = "CLIENT.QM_ORANGE";
MQQueueManager queueManager;
// Setup connection information
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = host;
queueProperties[MQC.PORT_PROPERTY] = port;
queueProperties[MQC.CHANNEL_PROPERTY] = channel;
try
{
// Attempt the connection
queueManager = new MQQueueManager(queueManagerName, queueProperties);
Console.WriteLine("Connected Successfully");
}
catch (MQException mexc)
{
// TODO: Setup other exception handling
throw new Exception(mexc.Message
+ " ReasonCode: " + mexc.ReasonCode
+ "--- see list of Reason Codes at http://russsutton.com/developer/?p=45 "
+ mexc.StackTrace, mexc);
}
}
|
The problem persists, even in my personal computer, which I also installed the software trying to get a different error this time.
When the computer executes the following line:
Code: |
queueManager = new MQQueueManager(queueManagerName, queueProperties);
|
It throws a Type initializer exception with the following message and stacktrace.
The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' threw an exception.
at System.Runtime.CompilerServices.RuntimeHelpers._RunClassConstructor(IntPtr type)
at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
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, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at IBM.WMQ.Nmqi.NmqiEnvironment.GetInstance(String name)
at IBM.WMQ.Nmqi.NmqiEnvironment.GetMQI(Int32 id)
at IBM.WMQ.MQQueueManager.Connect(String queueManagerName)
at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, Hashtable properties)
at Pactual.Calypso.TradeBus.MQSeriesAccess.Base.MQConnection.OpenConnection() in C:\felipe\Programming\Projects\pelife\pelife-shared\Pelife\Pelife.MQ.Learning\Base\MQConnection.cs:line 185
at Pactual.Calypso.TradeBus.MQSeriesAccess.Base.MQConnection.Connect(String pQueueManager, String pHostName, String pClientConn, String pConnectionType, Int32 port) in C:\felipe\Programming\Projects\pelife\pelife-shared\Pelife\Pelife.MQ.Learning\Base\MQConnection.cs:line 44
at Pactual.Calypso.TradeBus.MQSeriesAccess.Base.MQConnection..ctor(String pQueueManager, String pHostName, String pClientConn, Int32 port) in C:\felipe\Programming\Projects\pelife\pelife-shared\Pelife\Pelife.MQ.Learning\Base\MQConnection.cs:line 23
at Pelife.MQ.Learning.Program.Main(String[] args) in C:\felipe\Programming\Projects\pelife\pelife-shared\Pelife\Pelife.MQ.Learning\Program.cs:line 25
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The inner exception contains more details.
Message:
{"Object reference not set to an instance of an object."}
Stacktrace:
at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
at IBM.WMQ.Nmqi.UnmanagedNmqiMQ..cctor() |
|
Back to top |
|
 |
Vitor |
Posted: Fri Mar 16, 2012 9:50 am Post subject: Re: The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
pelife wrote: |
In my applications, I referenced the amqmdnet.dll |
Why did you elect not to use the XMS .NET components?
pelife wrote: |
static void Main(string[] args)
{
// Setup some test data
string queueManagerName = "QM_ORANGE";
string host = "127.0.0.1";
int port = 1415;
string channel = "CLIENT.QM_ORANGE";
|
Is this configuration working successfully on your queue manager? Have you tested it with one of the supplied client samples (or other means of your choosing)? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
pelife |
Posted: Fri Mar 16, 2012 12:48 pm Post subject: |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
It's now working but I don't know for sure which of the following actions was the right one.
I restarted my computer, tried to run my application again. Nops, same error.
I donwload and installed Websphere MQ (but this time, client only), I have already the client from the server installation. After the install, the same error persisted.
Anxious for a solution to my problem, I have accessed the samples directory and every .bat file I found, I executed. Most of them (the ones I checked) was only performing commands to compile the samples.
After that I checked the enviroment variables of my computer, I opened the MQSERVER to make sure it was pointing to my computer. It took a few seconds after i've saved the configurations to close the window. (This is probably the one)
Next time I run the application, it works.
Sorry for not supplying a real solution to the problem, but judging from the results I have found on google, this is not a recurring problem.
I'll try this solution at home and will post it again.[/b] |
|
Back to top |
|
 |
rekarm01 |
Posted: Fri Mar 16, 2012 1:01 pm Post subject: Re: The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
pelife wrote: |
Code: |
// Setup connection information
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = host;
queueProperties[MQC.PORT_PROPERTY] = port;
queueProperties[MQC.CHANNEL_PROPERTY] = channel; |
|
This doesn't seem like the proper way to add entries to a Hashtable. |
|
Back to top |
|
 |
mqsiuser |
Posted: Fri Mar 16, 2012 1:18 pm Post subject: Re: The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
rekarm01 wrote: |
pelife wrote: |
Code: |
// Setup connection information
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = host;
queueProperties[MQC.PORT_PROPERTY] = port;
queueProperties[MQC.CHANNEL_PROPERTY] = channel; |
|
This doesn't seem like the proper way to add entries to a Hashtable. |
When i used hashtables I create the key-value-pairs and then add them to the hashtable: hashtable.add(). _________________ Just use REFERENCEs |
|
Back to top |
|
 |
pelife |
Posted: Fri Mar 16, 2012 2:05 pm Post subject: |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
all the three ways work.
the syntax I used does the following:
if it exists, alter value for the given key.
if it doesn't exists, it will be added.
use the syntax Add(key, value)
use the syntax Add(new KeyValuePair(key, value))
It worked anyway. |
|
Back to top |
|
 |
pelife |
Posted: Fri Mar 16, 2012 6:48 pm Post subject: |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
Now it's definitely it ! Arriving at home, i just set the environment variable MQSERVER, changed the source code a little and was able to catch some MQExceptions due to authorization issues.
This time, I have used the source code from IBM documentation:
Code: |
using System;
using System.Collections.Generic;
using IBM.WMQ;
using System.Collections;
namespace LearningWebsphereMQ
{
// ===========================================================================
// Licensed Materials - Property of IBM
// 5724-H72
// (c) Copyright IBM Corp. 2003, 2005
// ===========================================================================
using System;
using System.Collections;
using IBM.WMQ;
class MQSample
{
// The type of connection to use, this can be:-
// MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
// MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
// MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
// MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
const String connectionType = MQC.TRANSPORT_MQSERIES_MANAGED;
// Define the name of the queue manager to use (applies to all connections)
const String qManager = "MQMGR";
// Define the name of your host connection (applies to client connections only)
const String hostName = "127.0.0.1";
// Define the name of the channel to use (applies to client connections only)
const String channel = "Q1.CONN";
/// <summary>
/// Initialise the connection properties for the connection type requested
/// </summary>
/// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
static Hashtable init(String connectionType)
{
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.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
break;
}
return connectionProperties;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
try
{
Hashtable connectionProperties = init(connectionType);
// Create a connection to the queue manager using the connection
// properties just defined
MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);
// Set up the options on the queue we want to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we want to open,and the open options
MQQueue system_default_local_queue =
qMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);
// Define a WebSphere MQ message, writing some text in UTF format
MQMessage hello_world = new MQMessage();
hello_world.WriteUTF("Hello World!");
// Specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
// same as MQPMO_DEFAULT
// Put the message on the queue
system_default_local_queue.Put(hello_world, pmo);
// Get the message back again
// First define a WebSphere MQ message buffer to receive the message
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.MessageId = hello_world.MessageId;
// Set the get message options
MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults
//same as MQGMO_DEFAULT
// Get the message off the queue
system_default_local_queue.Get(retrievedMessage, gmo);
// Prove we have the message by displaying the UTF message text
String msgText = retrievedMessage.ReadUTF();
Console.WriteLine("The message is: {0}", msgText);
// Close the queue
system_default_local_queue.Close();
// Disconnect from the queue manager
qMgr.Disconnect();
}
//If an error has occurred in the above,try to identify what went wrong.
//Was it a WebSphere MQ error?
catch (MQException ex)
{
Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
}
catch (System.Exception ex)
{
Console.WriteLine("A System error occurred: {0}", ex.ToString());
}
Console.ReadLine();
return 0;
}//end of start
}//end of sample
}
|
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0m0/index.jsp?topic=%2Fcom.ibm.mq.csqzav.doc%2Fun10490_.htm
Now I have some security issues to go through but the initial problem is solved. |
|
Back to top |
|
 |
Vitor |
Posted: Sat Mar 17, 2012 7:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
pelife wrote: |
Now it's definitely it ! Arriving at home, i just set the environment variable MQSERVER, changed the source code a little and was able to catch some MQExceptions due to authorization issues. |
Yes it is, because MQSERVER is used in preference to what's being defined in your code. There are good reasons why you'd want to use it (but not many), other good reasons why you'd want to have the details in your code and other reasons why you'd want to use a CCDT.
pelife wrote: |
This time, I have used the source code from IBM documentation: |
You've also used a different queue manager & channel name to your previous post.
pelife wrote: |
Now I have some security issues to go through but the initial problem is solved. |
The initial problem is more bypassed than fixed. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Mar 17, 2012 10:14 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You seem to be looking for a solution to distribute where the amq*net.dll would be enough.
Have you read the .NET manual and the client manual and specifically the parts about managed and unmanaged clients?
Think also about this
Code: |
// MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
const String connectionType = MQC.TRANSPORT_MQSERIES_MANAGED; |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
pelife |
Posted: Mon Mar 19, 2012 9:27 am Post subject: |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
Hello, thank you all for the feedback.
Vitor, yes, that was a different block of code, this was the one I was trying to run at home. The first I sent is the one I tried to run here at my office.
fjb_saper: I have read some stuff, I confess that I didn't read much but what I was trying to do was something really simple. Just the hello world stuff, now I am going to dig deeper in it.
Anyway, everything is ok now.
In time, this is the script my Websphere MQ administrator gave me to resolve authorization issues:
Code: |
SETMQAUT -m <QM NAME> -t qmgr -p <USR NAME> +allmqi +alladm
SETMQAUT -m <QM NAME> -n <QUEUE NAME> -t queue -p <USR NAME> +allmqi
|
Than ok |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Mar 19, 2012 9:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
pelife wrote: |
In time, this is the script my Websphere MQ administrator gave me to resolve authorization issues: |
Excellent. This is the person you should have talked to about authorization issues, your MQ administrator.
Very well done. |
|
Back to top |
|
 |
pelife |
Posted: Mon Mar 19, 2012 11:00 am Post subject: |
|
|
 Novice
Joined: 15 Mar 2012 Posts: 10 Location: Rio de Janeiro - BR
|
Except that I don't have one at home.
Thanks mqjeff |
|
Back to top |
|
 |
Pieterr |
Posted: Wed Dec 02, 2015 6:43 am Post subject: |
|
|
Newbie
Joined: 02 Dec 2015 Posts: 1
|
Hi,
I know that this is an old post but I'm curious to the answer as we're facing the same issue in a specific situation. We have the exact same error as described in this topic on one machine but not on the other and we can't seem to find any differences in the environment.
Since there wasn't really a solution to this problem but rather a workaround, can anyone point me in the right direction?
Thanks,
Pieterr |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|