0

I have this static string that works fine to Create a queue in MSMQ:

mqListener= @".\Private$\Trader";

MessageQueue.Create(mqListener);

but, when I try this I get invalid queue name error:

mqListener= @".\Private$\Trader";

suffx = "set-at-run-time";

newName = mqListener + suffx;

MessageQueue.Create(newName );
tom redfern
  • 30,562
  • 14
  • 91
  • 126
llqh
  • 1
  • Most likely you are setting illegal characters in your suffx variable. I tried out your code quickly in Linqpad and encountered no issues with those default values for the variables you listed above. Cannot reproduce is my observation. Can you try to catch the error and list it here with a try catch ? – Tore Aurstad Apr 12 '20 at 22:10

2 Answers2

1

This will work:

mqListener= ".\\Private$\\Trader";

suffx = "set-at-run-time";

newName = mqListener + suffx;

MessageQueue.Create(newName );

Evidently the @ is a compiler directive and the string class does not look at that...so the double // will work at run time

d219
  • 2,707
  • 5
  • 31
  • 36
0

That should be double backward slash; the single \ should be double.

mqListener= ".\\Private$\\Trader";
d219
  • 2,707
  • 5
  • 31
  • 36
llqh
  • 1