[rabbitmq-discuss] how to close a connection in dotnet?

Hubert Plociniczak hubert at lshift.net
Tue Aug 12 11:46:25 BST 2008


Hi Geoffrey,

I tried to reproduce your bug on Mono and everything was working
as expected.

Then I switched to .Net (native) and actually noticed your problem.
I guess there is something different with .Net environment (again)
and it does not behave as expected.

Thanks for reporting that!
I will fix that as soon as possible.

Hubert

Geoffrey Anderson wrote:
> Just a basic question on opening and closing the connection...
>
> When I call this line of C# code using the .net library 1.4.0 :
>
> mqConnection.Close();
>
> I quickly get this exception:
>
> System.ObjectDisposedException was unhandled
>   Message="Cannot access a disposed object.\r\nObject name:
> 'System.Net.Sockets.Socket'."
>   Source="System"
>   ObjectName="System.Net.Sockets.Socket"
>   StackTrace:
>        at System.Net.Sockets.TcpClient.set_ReceiveTimeout(Int32 value)
>        at RabbitMQ.Client.Impl.SocketFrameHandler_0_9.set_Timeout(Int32 value)
>        at RabbitMQ.Client.Impl.ConnectionBase.ClosingLoop()
>        at RabbitMQ.Client.Impl.ConnectionBase.MainLoop()
>        at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
>        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
> ContextCallback callback, Object state)
>        at System.Threading.ThreadHelper.ThreadStart()
>        
>        
>        
> Here is the code which established my connection before I called the Close method.
>  
> Is there a mistake in the way I set up the connection which might cause this socket
> error?  It seems to run fine and there are no exceptions except for the later Close
> statement.
>
>
>         void OpenOutputQueue()
>         {
>             mqFactory = new ConnectionFactory();
>             mqFactory.Parameters.UserName = Cfg("MessageQueueUserName");
>             mqFactory.Parameters.Password = Cfg("MessageQueuePassword");
>             mqFactory.Parameters.VirtualHost = Cfg("MessageQueueVirtualHost", "/");
>             mqFactory.Parameters.RequestedHeartbeat = 0;
>             //mqFactory.Parameters.RequestedHeartbeat = 20;
>             IProtocol mqProtocol = Protocols.FromEnvironment();
>             mqHost = Cfg("MessageQueueHost", "localhost");
>             mqConnection = mqFactory.CreateConnection(mqProtocol, mqHost);
>             mqModel = mqConnection.CreateModel();
>             mqTicket = mqModel.AccessRequest(Cfg("MessageQueueRealm"));
>             mqExchange = Cfg("MessageQueueExchange");
>             mqModel.ExchangeDeclare(mqTicket, mqExchange, ExchangeType.Direct);
>             mqQueueName = Cfg("MessageQueueName");
>             mqModel.QueueDeclare(mqTicket, mqQueueName, false);
>             mqRoutingKey = Cfg("MessageQueueRoutingKey");
>             mqModel.QueueBind(mqTicket, mqQueueName, mqExchange, mqRoutingKey,
> false, null);
>             mqConnection.AutoClose = false;
>         }
>
>
>
> Sorry to waste time if I missed something in the manuals.
>
> Thanks for reading.
>
> Geoffrey Anderson
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>   

-- 
 [][][] Hubert Plociniczak
   [][] LShift Ltd
 []  [] www.lshift.net





More information about the rabbitmq-discuss mailing list