My technical journal.

Maybe useful, maybe not.
posts - 105 , comments - 45 , trackbacks - 0

MSMQ error “Format name buffer supplied to the API was too small to fit the format name”

On Microsoft’s MSMQ forum, David Wellna got to the bottom of a problem being seen with not being able to use all 124 characters for a queue name.

Although the queue could be created at this length, it was not possible to change any of its properties without receiving a “Format name buffer supplied to the API was too small to fit the format name” error.

As discussed in this MSDN article, Queue Path Names, the full address for a queue is made up of 256 characters for the machine name and 124 for the queue name (including the characters “private$\” for private queues), giving a grand total of 380 characters.

It was found, though, that some internal functions in MSMQ were incorrectly assuming that the full address, not just the queue, occupied only 124 characters.

Here’s David’s findings:

I'm trying to create a private message queue with a pretty long name (101 characters excluding the private-prefix) which works well.
But when I am trying to set a property for that queue (at least at 'Authenticate') I get a MessageQueueException with the error code 'FormatNameBufferTooSmall':

{System.Messaging.MessageQueueException (0x80004005): Format name buffer supplied to the API was too small to fit the format name.
   at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath(String queuePath, Boolean throwException)
   at System.Messaging.MessageQueue.get_FormatName()
   at System.Messaging.MessageQueue.SaveQueueProperties()
   at System.Messaging.MessageQueue.set_Authenticate(Boolean value)
   at <MyCode>}

Using the .Net Reflector I found the problem to be located in the 'FormatName' property of the MessageQueue class which is used by a lot of methods and also in the 'SaveQueueProperties()' method which is called in a lot of property setters.

In the getter of 'FormatName' a call to the MSMQ COM API is made using a method in the 'SafeNativeMethods' class.

When calling this API-method (either IntMQInstanceToFormatName() or IntMQPathNameToFormatName()) an integer parameter called 'count' is passed into. The value of this parameter is hardcoded set to 124 prior to calling the method.
At first, this does not seem to be a problem as the documentation states that queues names may contain up to 124 characters but the method returns the format name of the queue containing more information as for example the machine name where the queue is located.
So, the method uses 124 characters as the max string length for the format name, not the queue name.

What I did then was to use Reflections to set the 'formatName' field of the newly created MessageQueue object to the correct format name returned by the same  API-method but with a greater value for 'count'. The property 'FormatName' now always returns the value of the internal field. (this is always done if 'formatName' is not null).

I still do not know whether there could be other problems resulting in this format name issue but as the MSMQ COM API is working, you probably could create your own .NET wrapper for that.

Great detective work, there.

Print | posted on Wednesday, January 26, 2011 2:17 PM |


No comments posted yet.
Post A Comment

Powered by: