Native API示例代码NativeAppWin中NMSConnectionFactory异常求助
问题原因与解决思路
核心问题
你遇到的TypeLoadException是版本不兼容导致的:
- Apache.NMS 2.0的
IConnectionFactory接口新增了CreateConnectionAsync异步方法; - 但搭配的Apache.NMS.ActiveMQ 1.8是旧版本,未实现这个新增的接口方法,最终引发类型加载失败。
解决方案
以下两种版本搭配方案二选一即可:
方案1:降级Apache.NMS到兼容版本
将NuGet中的Apache.NMS从2.0降级到1.8.x系列(推荐最新的1.8.1版本),这个版本和你当前使用的Apache.NMS.ActiveMQ 1.8完全兼容,接口方法一致,不会出现缺失实现的问题。
操作步骤:
- 卸载当前的
Apache.NMS2.0包; - 安装
Apache.NMS版本1.8.1。
方案2:升级Apache.NMS.ActiveMQ到兼容版本
将NuGet中的Apache.NMS.ActiveMQ从1.8升级到2.0.x及以上版本(比如2.0.1),新版本会完整实现Apache.NMS 2.0接口中的所有方法,包括CreateConnectionAsync。
操作步骤:
- 卸载当前的
Apache.NMS.ActiveMQ1.8包; - 安装
Apache.NMS.ActiveMQ版本2.0.1(或更高的稳定兼容版本)。
验证
修改版本后重新编译运行代码,StartSession方法创建连接工厂时的异常应该会消失。
异常详情:
Apache.NMS.NMSConnectionException HResult=0x80131500 Message=Could not create the IConnectionFactory implementation: Method 'CreateConnectionAsync' in type 'Apache.NMS.ActiveMQ.ConnectionFactory' from assembly 'Apache.NMS.ActiveMQ, Version=1.8.0.0, Culture=neutral, PublicKeyToken=82756feee3957618' does not have an implementation. Source=Apache.NMS StackTrace: at Apache.NMS.NMSConnectionFactory.CreateConnectionFactory(Uri uriProvider, Object[] constructorParams) at Apache.NMS.NMSConnectionFactory..ctor(Uri uriProvider, Object[] constructorParams) at NativeAppWin.Form1.StartSession() in C:\Projects\Testers\NativeAPI-DotNet-Demo\NativeAppWin\Form1.cs:line 67 at NativeAppWin.Form1.Form1_Load(Object sender, EventArgs e) in C:\Projects\Testers\NativeAPI-DotNet-Demo\NativeAppWin\Form1.cs:line 141 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.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) This exception was originally thrown at this call stack: [External Code] Inner Exception 1: TypeLoadException: Method 'CreateConnectionAsync' in type 'Apache.NMS.ActiveMQ.ConnectionFactory' from assembly 'Apache.NMS.ActiveMQ, Version=1.8.0.0, Culture=neutral, PublicKeyToken=82756feee3957618' does not have an implementation.
内容的提问来源于stack exchange,提问作者TravelDev
相关产品推荐
相关产品推荐

