Search code examples
c#.netnamed-pipes

InvalidOperationException while using NamedPipes on Windows XP and .Net 3.5


I am using a named pipe to communicate between two processes using .Net 3.5. This works fine on Windows 7, but somehow does not under Windows XP.

I am getting an InvalidOperationException there. Here is my attempt of translation of the german message: "Pipe handle has not been set. Did your PipeStream implementation call InitializeHandle?"

I have created a test project for this: http://www.chinery.de/dateien/NamedPipeTest.zip

In the application, you can hit "Connect" and will see the name of the Pipe. On the right hand side, you can enter a message that will be sent through the pipe, if all goes well.

As I have said, the problem only appears on Windows XP for me.

Does anyone have a clue on this?


Solution

  • I finally found the solution myself. It was the pipe client creation:

    NamedPipeClientStream pipeClient = new NamedPipeClientStream("localhost", PipeName, PipeDirection.InOut)
    

    I had to change this to: NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.InOut)

    (change server name from "localhost" to ".")

    This somehow worked on Windows 7, but not on XP. Now it finally works on both systems.