无法创建IConnectionFactory实现



我有一个windows服务。我使用Topshelf。启动时运行cs.Start()方法。

static void Main(string[] args)
{
var exitCode = HostFactory.Run(x =>
{
var assembly = new AssemblyInfo(Assembly.GetAssembly(typeof(Program)));
x.Service<Services.Producer>(s =>
{
s.ConstructUsing<Services.Producer>(cs => new Services.Producer(log));
s.WhenStarted(cs => cs.Start());
s.WhenStopped(cs => cs.Stop());
});
x.EnablePauseAndContinue();
x.EnableShutdown();
x.EnableServiceRecovery(r =>
{
r.OnCrashOnly();
r.RestartService(delayInMinutes: 0);
r.RestartService(delayInMinutes: 1);
r.RestartService(delayInMinutes: 5);
r.SetResetPeriod(days: 1);
});
x.SetServiceName(System.Text.RegularExpressions.Regex.Replace(assembly.Product, @"s+", ""));
x.SetDisplayName(assembly.ProductTitle);
x.SetDescription(assembly.Description);
x.AfterInstall(p =>
{
log.Info("xxxxxxxxxxx.");
});
x.AfterUninstall(() =>
{
log.Info("xxxxxxxxxxxx.");
});
x.OnException(ex =>
{
log.Error($"Error.", ex);
});
});
}

Start()方法调用另一个方法。实现这种异步方法见下文:

public void StartAsync(INmsService nmsService)
{
try
{
if (!nmsService.IsStarted)
{
var worker = new BackgroundWorker();
worker.WorkerSupportsCancellation = true;
worker.DoWork += (e, o) =>
{
try
{
nmsService.Start();
}
catch (Exception ex)
{
log.Error($"xxxx", ex);
}
};
worker.RunWorkerCompleted += (e, o) =>
{
};
worker.RunWorkerAsync();
}
}
catch
{
throw;
}
}

现在nmsService.Start()代码:

public void Start()
{
try
{
factory = new NMSConnectionFactory(Settings.Endpoint);
connection = factory.CreateConnection(Settings.UserName, Settings.Password);
connection.ClientId = $"{Settings.Name}Service";
session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
destination = SessionUtil.GetDestination(session, Settings.QueueName, DestinationType.Queue);
producer = session.CreateProducer(destination);
connection.Start();
}
catch (Exception ex)
{
throw ex;
}
}

但是,当运行实现时,这是一个例外:

"无法创建IConnectionFactory实现:Apache.NMS.ActiveMQ程序集的Apache.NMS_ActiveMQ.ConnectionFactory类型的CreateConnectionAsync方法,版本=1.8.0.0,区域性=中性,PublicKeyToken=82756feee3957618没有实现">

谢谢你的帮助!

我不知道错误的确切原因,但我找到的解决方案是将两个依赖项Apache.NMSApache.NMS.ActiveMQ恢复到以前的版本。我已经升级到v2.0.0v1.8.0。我已经将Apache.NMS降级为v1.8.0,将Apache.NMS.ActiveMQ降级为v1.7.2,问题已经解决。

最新更新