Jheferson
Jheferson

Reputation: 71

Could not create the IConnectionFactory implementation

I have a windows service. I using Topshelf. When started it is run a cs.Start() method.

        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() method call another method. Implementation this async method see below:

        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;
            }
        }

Now nmsService.Start() code:

        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;
            }
        }

But, when to run implementation, this a exception is a rised:

"Could not create the IConnectionFactory implementation: CreateConnectionAsync method on Apache.NMS.ActiveMQ.ConnectionFactory type of Apache.NMS.ActiveMQ assembly, Version=1.8.0.0, Culture=neutral, PublicKeyToken=82756feee3957618 does not have an implementation."

Thank for help!

Upvotes: 0

Views: 1029

Answers (1)

Jheferson
Jheferson

Reputation: 71

I don't know what exactly caused the error, but the solution I found was to revert the two dependencies Apache.NMS and Apache.NMS.ActiveMQ to previous versions. I had upgraded to v2.0.0 and v1.8.0. I've downgraded Apache.NMS to v1.8.0 and Apache.NMS.ActiveMQ to v1.7.2 and the problem was fixed.

Upvotes: 3

Related Questions