C# 无法使用模拟加载mqe.dll

C# 无法使用模拟加载mqe.dll,c#,dll,ibm-mq,C#,Dll,Ibm Mq,我正在尝试使用在系统上创建的本地用户连接到IBM MQ队列管理器 我使用的是WinServer2008R2,IBMMQ客户端和服务器版本是8.0.0.6 为了以本地用户身份运行代码,我实现了模拟。现在,当我模拟用户并尝试连接时,我发现下面的连接错误。当我以其他用户(本地用户)的身份运行VisualStudio时,它会工作,但当我使用模拟时则不会 以下是跟踪: System.TypeInitializationException was unhandled HResult=-21462330

我正在尝试使用在系统上创建的本地用户连接到IBM MQ队列管理器

我使用的是WinServer2008R2,IBMMQ客户端和服务器版本是8.0.0.6

为了以本地用户身份运行代码,我实现了模拟。现在,当我模拟用户并尝试连接时,我发现下面的连接错误。当我以其他用户(本地用户)的身份运行VisualStudio时,它会工作,但当我使用模拟时则不会

以下是跟踪:

 System.TypeInitializationException was unhandled
  HResult=-2146233036
  Message=The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
  Source=amqmdnet
  TypeName=IBM.WMQ.MQQueueManager
  StackTrace:
       at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName)
       at MQExample.MQTest.ConnectMQ(String strQueueManagerName, String strQueueName, String strChannelInfo) in D:\Adidas\MQExample\MQExample\MQExample\MQTest.cs:line 83
       at MQExample.Form1.button1_Click(Object sender, EventArgs e) in D:\Adidas\MQExample\MQExample\MQExample\Form1.cs:line 33
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at MQExample.Program.Main() in D:\Adidas\MQExample\MQExample\MQExample\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146232828
       Message=Exception has been thrown by the target of an invocation.
       Source=mscorlib
       StackTrace:
            at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
            at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
            at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
            at System.Activator.CreateInstance(Type type, Boolean nonPublic)
            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.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.TraceConstructor(String objectId, String sccsid)
            at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
            at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
            at IBM.WMQ.MQQueueManager..cctor()
       InnerException: 
            HResult=-2146232828
            Message=Exception has been thrown by the target of an invocation.
            Source=amqmdnet
            StackTrace:
                 at IBM.WMQ.MQCommonServices..ctor()
            InnerException: 
                 HResult=-2146233088
                 Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\
                 Source=amqmdnet
                 StackTrace:
                      at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
                 InnerException: 
实现它的代码:

 using (new Tools.Impersonator("iibadmin", ".", "Test@1234"))
                    {
                        string userafter = WindowsIdentity.GetCurrent().Name;
                        MQQueueManager queueManager = null;
                        queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);

                        int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
                        queue = queueManager.AccessQueue(QueueName, openOptions);
                        int depth = queue.CurrentDepth;
                        queueMessage = new MQMessage();
                        queueMessage.Format = MQC.MQFMT_STRING;
                        queueGetMessageOptions = new MQGetMessageOptions();
                        queue.Get(queueMessage, queueGetMessageOptions);
                        strReturn =
                        queueMessage.ReadString(queueMessage.MessageLength);
                        queue.Close();

                        queueManager.Disconnect();
                    }

您的模拟用户可能没有MQ环境设置

i、 e.环境变量:

PATH
LIB
MQ_JAVA_DATA_PATH
MQ_JAVA_INSTALL_PATH
MQ_JAVA_LIB_PATH
MQ_JRE_PATH
如果您运行的是32位.NET,则需要指向32位MQ环境,如wise for 64位

i、 e.mqe.dll位于:

C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll
C:\Program Files\IBM\WebSphere MQ\bin64\mqe.dll

因此,最好了解您正在运行什么以及需要设置什么MQ环境。

您的模拟用户可能没有MQ环境设置

i、 e.环境变量:

PATH
LIB
MQ_JAVA_DATA_PATH
MQ_JAVA_INSTALL_PATH
MQ_JAVA_LIB_PATH
MQ_JRE_PATH
如果您运行的是32位.NET,则需要指向32位MQ环境,如wise for 64位

i、 e.mqe.dll位于:

C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll
C:\Program Files\IBM\WebSphere MQ\bin64\mqe.dll

因此,最好知道您正在运行什么以及需要设置什么MQ环境。

文件
C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll是否存在?模拟用户是否有权访问该文件?您希望使用模拟运行它的原因是什么?以这种方式使用模拟将表明队列管理器上的SVRCONN通道不安全,并且只接受您在服务器上模拟的有效用户ID。使用MQv8,您可以向队列管理器发送用户名和密码,如果安装程序允许,它将验证并使用该ID来确定服务器上的MQ访问,无需模拟,并且由于您正在进行身份验证,因此安全性更好。文件
C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll是否存在?模拟用户是否有权访问该文件?是,该文件确实存在,并且模拟用户有权访问该文件。当VisualStudio作为不同的用户(我模拟的本地用户)运行时,它就像黄油一样工作。当我将其模拟为“运行”时,同样的方法不起作用。我使用的是MQ版本8.0.0.6。MQ服务器中的用户未设置密码,它只有用户名。我无法仅设置用户名并连接到MQUEManager。我希望你的意思是在hashtable属性中设置userid属性和密码。您能告诉我是否可以仅使用用户名完成此操作吗?正如我所说,它作为您模拟的用户工作这一事实对于安全性来说是一个坏兆头,因为它表明队列管理器刚刚接受断言的用户id。使用IBM MQ Classes for Java或JMS,断言您想要的任何id都是微不足道的。对于其他API,如.NET,您需要在该名称的用户下运行以断言id,但如果您有权创建本地用户,这也很简单。实际上,通过
CONNAUTH
和使用
ADOPTCTX(YES)
验证ID和密码意味着您现在也需要密码来连接。如果您想继续排除模拟不存在的原因,我建议您在服务器上启用MQ跟踪。另一个选项是,基于它正在查找
mqe.dll
的事实,它表示它已成功调用
amqmdnet.dll
,但正在非托管模式下运行,这意味着它需要作为客户端安装一部分的其他非.NET dll。如果在托管模式下运行,则不需要任何dll,除了
amqmdnet.dll
。文件
C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll
是否存在?模拟用户是否有权访问该文件?您希望使用模拟运行它的原因是什么?以这种方式使用模拟将表明队列管理器上的SVRCONN通道不安全,并且只接受您在服务器上模拟的有效用户ID。使用MQv8,您可以向队列管理器发送用户名和密码,如果安装程序允许,它将验证并使用该ID来确定服务器上的MQ访问,无需模拟,并且由于您正在进行身份验证,因此安全性更好。文件
C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll是否存在?模拟用户是否有权访问该文件?是,该文件确实存在,并且模拟用户有权访问该文件。当VisualStudio作为不同的用户(我模拟的本地用户)运行时,它就像黄油一样工作。当我将其模拟为“运行”时,同样的方法不起作用。我使用的是MQ版本8.0.0.6。MQ服务器中的用户未设置密码,它只有用户名。我无法仅设置用户名并连接到MQUEManager。我希望你的意思是在hashtable属性中设置userid属性和密码。您能告诉我是否可以仅使用用户名完成此操作吗?正如我所说,它作为您模拟的用户工作这一事实对于安全性来说是一个坏兆头,因为它表明队列管理器刚刚接受断言的用户id。使用IBM MQ Classes for Java或JMS,断言您想要的任何id都是微不足道的。对于其他API,如.NET,您需要在该名称的用户下运行以断言id,但如果您有权创建本地用户,这也很简单。实际上,通过
CONNAUTH
和使用
ADOPTCTX(YES)
验证ID和密码意味着您现在也需要密码来连接。如果您想继续排除模拟不存在的原因,我建议您在服务器上启用MQ跟踪。另一个选项是,基于它正在查找
mqe.dll
的事实,它表示它已成功调用
amqmdnet.dll
,但正在非托管模式下运行,这意味着它需要作为客户端安装一部分的其他非.NET dll。如果在托管模式下运行,则不需要任何dll,除了
amqmdnet.dll
。如果出现不同位(32-64)的问题,则不应使用