MessageQueue problems under .net 3  
Author Message
David L1





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

Hi,

I recently switched to the version 3 framework with SDK build 5536.0.2 and I'm having some issues wth code that uses the MessageQueue class.

Firstly, MessageQueue.CreateCursor() sometimes throws a MessageQueueException with the message 'Remote computer is not available'. It's not absolutely consistent and occasionally works correctly. I still have the code compiled against the V2 framework on another machine, and pointer at the same remote, public queue, it always works.

More worrying is what happens next. Sometime later - presumably on the next garbage collect - a NullReferenceException is thrown. If I catch this in the de****, I can see the exception is thrown from System.Messaging.Cursor.Finalize(). It appears the garbage collector is attempting to dispose the cursor which failed to create properly. Since this happens inside the garbage collector, there's no way to catch the exception and the program exits.

Any assistance welcome!

David




.NET Development33  
 
 
David L1





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

Did some more research on this using reflector. The NullreferenceException problem is caused by the following.

The Cursor is created by

internal Cursor(MessageQueue queue)
{
   CursorHandle handle1;
   int num1 = SafeNativeMethods.MQCreateCursor(queue.MQInfo.ReadHandle, out handle1);
   if (MessageQueue.IsFatalError(num1))
   {
      throw new MessageQueueException(num1);
   }
   this.handle = handle1;
}
Note that if MQCreateCursor returns a fatal error, this.handle is not set
When the garbage collector collects the failed cursor, the following sequence happens
~Cursor()
{
   this.Dispose(false);
}
private void Dispose(bool disposing)
{
   this.Close();
   this.disposed = true;
}
public void Close()
{
   this.handle.Close();
}

Since the ctor does not set handle, this.handle.Close() is a null referencs.

Sorry guys, this one's your problem. Now if someone can only tell me why the cursor open is failing in the first place. Odd since I can write to and read from the queue. It's just opening a cursor to display the queue contents that's failing, and only sometimes.

David


 
 
David L1





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

Helloooo

Some sort of comment would be nice

David



 
 
Jorg Jooss - MSFT





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

This forum is about network programming, not Enterprise Services or .NET 3.0. Did you try posting this question in one of the Vista forums
 
 
David L1





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

MessageQueue is a class that's been in the framework for some time. It is not Vista specific. Since I'm using the queue to communicate across a network - not an uncommon scenario - I would have thought Networking and Communication was the correct place.

Still I'll try somewhere else.

David



 
 
Marten Gustafsson





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

I get the same error when I unplug the network. It is bit annoying but not a big deal. Did you get any resolution to this /M
 
 
Marten Gustafsson





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

There is a workaround. Before creating the cursor, just try to peek the queue. If there is no contact with active directory an exception will be thrown and the create cursor call will not be reached. If the peek succeeds, there is a big chance the create cursor call will succeed.

Of course there is a very small chance of a race condition, if contact with active directory is lost between the calls.

/M


 
 
Marten Gustafsson





PostPosted: .NET Framework Networking and Communication, MessageQueue problems under .net 3 Top

I get the same error when I unplug the network. It is bit annoying but not a big deal. Did you get any resolution to this /M

I get this problem on Windows XP SP2, all relevant patches installed as of today.

/M