-1

System.IO.Pipes.NamedPipeServerStream class throws IOException and the documentation says The maximum number of server instances has been exceeded. This message is not very clear to me. Can someone explain it in terms of I can understand? Does it mean that the same code is being executed by two different processes or something like that? How can I avoid it if it happens rarely?

I am using the following constructor:

int maxNumberServerInstance = 1;
new NamedPipeServerStream(name, PipeDirection.InOut, maxNumberServerInstance , PipeTransmissionMode.Message, PipeOptions.None, bufferSize, bufferSize, pipeSecurity);

I get IOException.

Barış Akkurt
  • 2,255
  • 3
  • 22
  • 37
  • Code please... so we can see what you are doing – TheGeneral Feb 07 '19 at 08:20
  • Post the full exception text, not just the type name and message. You can get it easily with `Exception.ToString()`. This shows which method actually threw and the call stack that led to it. Post the code too. – Panagiotis Kanavos Feb 07 '19 at 08:21
  • Look at the docs for the NamedPipeServerStream class. Note that it has constructors that take a *maxNumberOfServerInstances* argument. That maximum. – Hans Passant Feb 07 '19 at 08:28

1 Answers1

0

Let's visit the documentation.

NamedPipeServerStream Class

Exceptions

IOException The maximum number of server instances has been exceeded.

NamedPipeServerStream.MaxAllowedServerInstances Field

Represents the maximum number of server instances that the system resources allow.

Remarks

Use the MaxAllowedServerInstances when creating a NamedPipeServerStream object to set the maximum number of server instances that the system resources allow.

In short the error is telling you that the maximum amount of instances has been created.

You will get this if you have used the default constructor with just the name, additionally you will get a pipe with the following characteristics:

  • A default pipe direction of InOut.

  • The maximum number of server instances that share the same name set to 1.

  • A PipeTransmissionMode value of Byte.

  • A PipeOptions value of None.

  • Default input and output buffer sizes.

  • No pipe security.

  • A HandleInheritability value of None.

  • No specified additional PipeAccessRights.

At minimum you would want to use the following constructor if you need more than one instance:

NamedPipeServerStream(String, PipeDirection, Int32)

Parameters

  • pipeName String

    • The name of the pipe.
  • direction PipeDirection

    • One of the enumeration values that determines the direction of the pipe.
  • maxNumberOfServerInstances Int32

    • The maximum number of server instances that share the same name. You can pass MaxAllowedServerInstances for this value.

Lastly, if you are getting this error and you have only one instance, you probably have a subtle problem with how you are creating them.

Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
TheGeneral
  • 79,002
  • 9
  • 103
  • 141