factory.CreateConnection() generates a None of the specified endpoints were reachable;

Viewed 635

We have a simple RabbitMQ .NET Client in ASP.NET Web App run under IIS 8. We do not use any SSL and the connection code is simple.

var factory = new ConnectionFactory()
{
    HostName = hostname,
    UserName = username,
    Password = password,
    VirtualHost = vhost,
    Port = 5672
};

var connection = factory.CreateConnection();

The last line generates the following exception

Exception Occurred
Type: RabbitMQ.Client.Exceptions.BrokerUnreachableException
Message: None of the specified endpoints were reachable
Stack Trace:    at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) in /_/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs:line 505
   at Org.Prod.Dependency.Concrete.Queuing.RabbitMqProdMessenger.SendMessage[TMessage](String hostname, String username, String password, String vhost, String target, TMessage message, Boolean targetIsExchange)
Source: RabbitMQ.Client

Inner Exception

Type: System.IO.IOException
Message: connection.start was never received, likely due to a network timeout
Stack Trace:    at RabbitMQ.Client.Framing.Impl.Connection.StartAndTune() in /_/projects/RabbitMQ.Client/client/impl/Connection.cs:line 1074
   at RabbitMQ.Client.Framing.Impl.Connection.Open(Boolean insist) in /_/projects/RabbitMQ.Client/client/impl/Connection.cs:line 707
   at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IFrameHandler fh) in /_/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs:line 646
   at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) in /_/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs:line 495
Source: RabbitMQ.Client

Interestingly, when the same code is put in a console app and the binaries are shipped to the same server running the App, the console app connects fine and is able to publish messages.

What is wrong with Web Application trying to do the same thing the console app is doing?

2 Answers

It was an assembly binding failure of System.Threading.Tasks.Extensions, our exception logger was not logging the InnerException

Exception information: 
    Exception type: FileLoadException 
    Exception message: Could not load file or assembly 'System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection..ctor(ConnectionFactory factory, String clientProvidedName)
   at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) in /_/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs:line 494

Very poor misleading error message.

In my case I received the exact same exception when calling factory.CreateConnection(); I am using RabbitMQ.Client 6.2.1 in a library that was dependant on System.Buffers 4.5.1 and my main assembly referenced System.Buffers 4.4.0, updated my main assembly to reference version 4.5.1 of System.Buffers, which involved a lot of other dependent Microsoft. and System. assemblies being removed first before I could remove then re-add System.Buffers via NuGet Package Manager as this told me I had 4.5.1 when my .csproj file said it was referencing 4.4.0. Once this reference issue was resolved the problem went away and I could connect to the RabbitMQ server.

Related