“IBM.WMQ.Nmqi.BindingsNmqiMQ”的类型初始值设定项引发了异常

时间:2016-06-10 10:12:46

标签: .net ibm-mq

当尝试以绑定模式连接到MQ时(我在本地设置了服务器),我得到以下异常:

 System.TypeInitializationException: The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
   at IBM.WMQ.Nmqi.BindingsNmqiMQ..cctor()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   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, StackCrawlMark& stackMark)
   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 Project.MQConnector.CreateConnectAndAddQueueManager(QueueManagerConnectionDetails connDetails)

尝试连接到队列管理器时发生错误,如下所示:

构造

Friend queueManagerConnectionProperties As New Hashtable()
queueManagerConnectionProperties.Add(MQC.THREAD_AFFINITY_PROPERTY, True)
If My.Settings.MQConnectAsClient Then
    queueManagerConnectionProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT)
Else
    queueManagerConnectionProperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_BINDINGS)
End If

queueManagerConnectionProperties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_HANDLE_SHARE_BLOCK Or MQC.MQCNO_RECONNECT_Q_MGR) ' have handle-sharing with call blocking

在CreateConnectAndAddQueueManager方法中(其中connDetails只是端口,主机,名称等的存储):

 Dim specificQMConnProperties As Hashtable = CType(queueManagerConnectionProperties.Clone(), Hashtable)
 specificQMConnProperties.Add(MQC.CHANNEL_PROPERTY, connDetails.Channel)
 specificQMConnProperties.Add(MQC.CONNECTION_NAME_PROPERTY, connectionName)
 Dim qmgr As MQQueueManager = Nothing

 Try
     qmgr = New MQQueueManager(connDetails.Name, specificQMConnProperties)
 Catch ex As MQException
     ' error handling
 End Try

我有以下环境变量:

NMQ_MQ_LIB=mqm.dll

当我使用托管连接(NMQ_MQ_LIB=managed;并且未设置MQC.TRANSPORT_PROPERTY)进行连接时,它可以正常工作。

有什么想法吗?

- 编辑 -

C:\Program Files\IBM\MQSI\9.0.0.2>dspmqver -a
Name:        WebSphere MQ
Version:     7.5.0.6
Level:       p750-006-160226
BuildType:   IKAP - (Production)
Platform:    WebSphere MQ for Windows
Mode:        32-bit
O/S:         Windows 7 Enterprise x64 Edition, Build 7601: SP1
InstName:    Installation1
InstDesc:
Primary:     No
InstPath:    C:\Program Files (x86)\IBM\WebSphere MQ
DataPath:    C:\Program Files (x86)\IBM\WebSphere MQ
MaxCmdLevel: 750
LicenseType: Production
AMQ8351: WebSphere MQ Java environment has not been configured correctly.
AMQ8351: WebSphere MQ Java environment has not been configured correctly.

Name:        IBM WebSphere MQ custom channel for Windows Communication Foundation
Version:     7.5.0.6
Level:       wn750-006-151116
Build Type:  Production


Name:        IBM Message Service Client for .NET (XMS .NET)
Version:     2.5.0.6
Level:       nn250-006-151116
Build Type:  Production


Name:        IBM Global Security Kit for WebSphere MQ
Version:     8.0.14.53
Build Type:  Production
Mode:        32-bit

Name:        IBM Global Security Kit for WebSphere MQ
Version:     8.0.14.53
Build Type:  Production
Mode:        64-bit

1 个答案:

答案 0 :(得分:3)

查看您的最新评论。您在GAC中有一些不需要的条目。你需要做一些清理工作。

1)打开命令提示符。

2)运行amqiregisterdotnet.cmd /u命令取消注册MQ .NET程序集。

3)检查Windows GAC MQ .NET程序集。确保没有MQ .NET条目。如果有,请尝试使用gacutil命令手动取消注册。

4)然后运行命令amqiregisterdotnet.cmd再次注册程序集。

希望这有帮助。