SyntaxHighlighter

Friday, July 11, 2008

Named pipes issue: System.UnauthorizedAccessException: Access to the path is denied.

After yesterday's triumphant discovery I had a nightmare of a day trying to figure out why my client couldn't connect to the server. Time and time again, the following exception was raised:

System.UnauthorizedAccessException: Access to the path is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Pipes.NamedPipeClientStream.Connect(Int32 timeout)
at System.IO.Pipes.NamedPipeClientStream.Connect()
And in the debug output window:
A first chance exception of type 'System.UnauthorizedAccessException' occurred in System.Core.dll

My best googling skills couldn't find an answer for this one and I ended up trying to change the permission for the NamedPipeServerStream and venturing down the wrong path by changing the PipeAuditRule and PipeAccessRule settings.

In the end turned out my PipeDirection had to be set to InOut, even though I was only streaming information from the Server, and not receiving information.

Here's the winning line of code:

NamedPipeServerStream Pipe = new NamedPipeServerStream(PipeName, PipeDirection.InOut, 1,
PipeTransmissionMode.Message, PipeOptions.None);

7 comments:

Anonymous said...

Thanks!
The MS example code is WRONG. And so is the code at: http://www.ehow.com/how_6053913_pass-visual-basic-application-another.html

It's simply amazing how poor the MS documentation is!

Folks like you are what makes life of a programmer tolerable.

Maurizio said...

Thank you! you saved me a lot of time!

Thomas said...

"#¤%"! Thanks :)

Kevin said...

Another satisfied customer. Thank you so much!

Anonymous said...

THANK YOU SO MUCH

Unknown said...

wow ^^ thank you

Anonymous said...

Ditto! Thank you. You saved me hours.