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.
|