Home Dashboard Directory Help

PowerShell functions cannot return System.Messaging.MessageQueue objects by Neil Barnwell



Sign in
to vote
Type: Bug
ID: 783463
Opened: 4/11/2013 9:15:14 AM
Access Restriction: Public
User(s) can reproduce this bug


Any given PowerShell function that successfully creates an instance of System.Messaging.MessageQueue is not able to return that object, by any means.
Sign in to post a comment.
Posted by Bartek Bielawski on 5/31/2013 at 1:41 PM
Not sure if that would work here - you may want to use unary comma to return IEnumerables:
function foo {
, $out
Posted by Neil Barnwell on 4/11/2013 at 3:49 PM
I'm an idiot. It's not a bug, but it's interesting. Because `System.Messaging.MessageQueue` implements `System.Collections.IEnumerable` by enumerating it's messages, the behaviour I was seeing was that PowerShell was actually reading the messages off the newly-created queues and putting them into the pipeline rather than the queue objects themselves. Of course because the queues were new, they were empty, so there was nothing passed on down the pipeline.

I just spent most of this afternoon and some hours this evening working this out. I am not proud of myself.
Sign in to post a workaround.
Posted by Neil Barnwell on 4/11/2013 at 9:19 AM
You could return the System.Messaging.MessageQueue.QueueName property instead, and any consumers of the function can then initialise their own System.Messaging.MessageQueue objects from that (e.g. in later functions in the pipeline).
File Name Submitted By Submitted On File Size  
PowerShell Issue 783463.ps1.txt 4/11/2013 919 bytes