locked
What is the real limit of private queue name length (.NET 2.0)? RRS feed

  • Question

  • I ran across am unexpected behavior of MSMQ (XP/2003, .NET 2.0), when queue name longer that some limit does not work.

    I fount this: http://msdn.microsoft.com/en-us/library/ms706083(v=VS.85).aspx, which states that maximum is 124.

    My working queues are ~70 characters long; working with no issues.

    If queue name length is 108 characters I get the following:

    1. Attempt to open queue results in The queue does not exist or you do not have sufficient permissions to perform the operation.

    2. Attempt to create queue results in Format name buffer supplied to the API was too small to fit the format name.

    3. In both cases above exception is thrown by the same method: System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath

    4. Queue is in fact created with full non-truncated name.

     

    So what's the name limit for private queue name?

    Does this limit include machine name?  My queue names (which I count characters in) look like .\Private$\ABCDEF...

     

    TIA.

    Monday, November 8, 2010 5:42 PM

Answers

  • Well, I kind of found a workaround which is actually more a 'dirty hack'.

    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.

    Hope, I could help.

    David

    Wednesday, January 26, 2011 10:12 AM

All replies

  • Yes, John, I came across this http://blogs.msdn.com/b/johnbreakwell/archive/2007/05/01/how-long-msmq-queue-names-are-displayed-or-not.aspx which looks to be the source.  The only difference is that these are talking about public queue names.

    Does the same applies to private?  I mean, I don't like these different statements and different behaviors; I want some limit, which shall work across Windows XP/Vista/7/2003/2008/not-so-distant-future whatever it is; I can live with 63 characters as long as it is confirmed.

    Thanks.

    Monday, November 8, 2010 11:41 PM
  • Both Blog posts are the same; the original on MSDN was written by me and I have permission to copy the content to my new blog. The new post has working pictures too.

    As described in the MSDN link you provided, the queue name can be up to 124 characters. This is independent of operating system/MSMQ version.
    Note that for private queues this space has to allow for "Private$\" so the maximum length for private queue names is less than that for public ones.

    I've created a sample queue and am able to send to .\private$\{{115 char queue name}} and servername\private$\{{115 char queue name}} using an old test app. The app is in C++, not .NET 2 though.

    The machine name is not included in the 124 character limit. The full path name limit should be 256 (computer name) + 124 (queue name) = 380 Unicode characters.

    Is your code executing locally on local queues?

    Do you have code to share that demonstrates the problem?

    Cheers
    John Breakwell

     

     

    Tuesday, November 9, 2010 1:44 AM
  • Thanks for some clarification, John.

    My code is too big and complex to post.  I'll come up with some test bare bones later and post it here.

    Tuesday, November 9, 2010 4:57 PM
  • I look forward to trying it out.

    Cheers

    John

    Thursday, November 11, 2010 2:42 PM
  • John, sorry, I'm busy with other project now, please don't expect anything from me soon.

    Thanks.

    Thursday, November 11, 2010 6:26 PM
  • No problem. I'll see if I can set up a repro based on what you've said so far.
    Friday, November 12, 2010 1:35 PM
  • Hi John,

    I ran into the same problem. Were you able to reproduce it?
    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>}

    I'd appreciate any help or suggestions you could provide since shorten the queue name is not really an option, we need to provide a lot of information in the name.

    Thanks,
    David

    Tuesday, January 25, 2011 10:16 AM
  • Well, I kind of found a workaround which is actually more a 'dirty hack'.

    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.

    Hope, I could help.

    David

    Wednesday, January 26, 2011 10:12 AM
  • Hi David,

    That's a good catch.

    Definitely looks like a bug where formatname and queuename have been taken to be the same thing. Count should, of course, be 380.

    Cheers

    John Breakwell

    Wednesday, January 26, 2011 1:59 PM