Skip to content

Fix: Validate MessageQueue path in constructors#14

Open
michaelsw95 wants to merge 1 commit into
weloytty:developfrom
michaelsw95:fix-path-validation
Open

Fix: Validate MessageQueue path in constructors#14
michaelsw95 wants to merge 1 commit into
weloytty:developfrom
michaelsw95:fix-path-validation

Conversation

@michaelsw95

Copy link
Copy Markdown

When trying to set a MessageQueue up locally I inadvertently passed a WCF NetMsmqBinding URI instead of a MSMQ path.

Later when associating a ReceiveCompleted message handler I got an exception from the library

`System.ArgumentOutOfRangeException: 'length ('-1') must be a non-negative value. Arg_ParamName_Name ArgumentOutOfRange_ActualValue'

var test = new MessageQueue("net.msmq://localhost/private/test");

test.ReceiveCompleted += new ReceiveCompletedEventHandler(Handle); // throws

After some digging I found the issue was related to the FormatName property being set from ResolveFormatNameFromQueuePath. So I knew it was the queue path that was then wrong and fixed my implementation

There is existing validation in the class for Path but the constructor bypasses this by setting the backing path field instead.

This PR is a suggestion to set the Path property instead which would trigger the validation. Perhaps helping a future dev find their mistake sooner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant