SyntaxHighlighter

Showing posts with label IPC. Show all posts
Showing posts with label IPC. Show all posts

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);

Thursday, July 10, 2008

.NET IPC through Named Pipe Servers

I've been struggling to get my own IPC server and client going. The work was based on this great post on The Code Project. Even though the article was very useful, I found the code to be a bit clunky.

I restructured a lot of it into very neat client / server structure. During debugging, I stumbled onto this "new" addition in the .Net 3.5 Framework. Named pipes are neatly integrated, so no need for my client and server anymore. Doh!

Oh well, I only lost a day's worth of coding, and at least I can rest assured that this part of my project will be quite stable.