我正在尝试将 C#.Net 项目转换为 Mono。在 Mono 中不支持 NamedPipeServerStream 和 NamedPipeClientStream 类并抛出 Unhandle 异常。你能帮帮我吗?
代码:
class Program
{
static string _PipeName = "testPipe";
static void Main(string[] args)
{
ListenForPipeServer();
}
static void ListenForPipeServer()
{
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(
_PipeName,
PipeDirection.InOut,
2,
PipeTransmissionMode.Message,
PipeOptions.None
))
{
StreamReader sr = new StreamReader(pipeServer);
StreamWriter sw = new StreamWriter(pipeServer);
do
{
try
{
pipeServer.WaitForConnection();
sw.WriteLine("Testing");
sw.Flush();
pipeServer.WaitForPipeDrain();
Console.WriteLine(sr.ReadLine());
}
catch (Exception)
{
throw;
}
finally
{
pipeServer.WaitForPipeDrain();
if (pipeServer.IsConnected) pipeServer.Disconnect();
}
} while (true);
}
}
}
未处理的异常:
System.IO.IOException:创建命名管道时出错:错误代码 -1
在 System.IO.Pipes.UnixNamedPipe.EnsureTargetFile(System.String 名称)[0x0001f] 在 /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono -2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/System.Core/System.IO.Pipes/PipeUnix.cs:131 在 System.IO.Pipes .UnixNamedPipeServer..ctor(System.IO.Pipes.NamedPipeServerStream 所有者,System.String pipeName,Int32 maxNumberOfServerInstances,PipeTransmissionMode 传输模式,PipeAccessRights 权限,PipeOptions 选项,Int32 inBufferSize,Int32 outBufferSize,HandleInheritability 可继承性)[0x00012] in /Users/builder/数据/车道/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/ mcs/class/System.Core/System.IO.Pipes/PipeUnix.cs:265 在 System.IO.Pipes。NamedPipeServerStream..ctor (System.String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, System.IO.Pipes.PipeSecurity pipeSecurity, HandleInheritability 可继承性, PipeAccessRights additionalAccessRights) [0x0004b] in /Users/ builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11。 git/mcs/class/System.Core/System.IO.Pipes/NamedPipeServerStream.cs:100 在 System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName,PipeDirection 方向,Int32 maxNumberOfServerInstances,PipeTransmissionMode 传输模式,PipeOptions 选项, Int32 inBufferSize, Int32 outBufferSize, System.IO.Pipes.PipeSecurity pipeSecurity,HandleInheritability 可继承性)[0x00000] in :0 at System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName,PipeDirection 方向,Int32 maxNumberOfServerInstances,PipeTransmissionMode 传输模式,PipeOptions 选项,Int32 inBufferSize,Int32 outBufferSize,System.IO.Pipes。 PipeSecurity pipeSecurity) [0x00000] in :0 at System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize) [0x00000] in :0在 System.IO.Pipes.NamedPipeServerStream..ctor(System.String pipeName,PipeDirection 方向,Int32 maxNumberOfServerInstances,PipeTransmissionMode 传输模式,PipeOptions 选项)[0x00000] 中:0 at (wrapper remoting-invoke-with-check) System.IO.Pipes.NamedPipeServerStream:.ctor (string,System.IO.Pipes.PipeDirection,int,System.IO.Pipes.PipeTransmissionMode,System.IO.Pipes.PipeOptions ) 在 ConsoleTestPipeApp1.Program.ListenForPipeServer () [0x00000] 在 /Users/Vadivelu/Project/Service_Test/ConsoleTestPipeApp1/ConsoleTestPipeApp1/Program.cs:21 在 ConsoleTestPipeApp1.Program.Main (System.String[] args) [0x00000] 在 / Users/Vadivelu/Project/Service_Test/ConsoleTestPipeApp1/ConsoleTestPipeApp1/Program.cs:16 [错误] 致命的未处理异常:System.IO.IOException:创建命名管道时出错:System.IO.Pipes.UnixNamedPipe.EnsureTargetFile 处的错误代码 -1 (System.String 名称)[0x0001f] 在 /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono -2.10。11/_build/mono-2.10.11.git/mcs/class/System.Core/System.IO.Pipes/PipeUnix.cs:131 在 System.IO.Pipes.UnixNamedPipeServer..ctor (System.IO.Pipes.NamedPipeServerStream所有者,System.String pipeName,Int32 maxNumberOfServerInstances,PipeTransmissionMode 传输模式,PipeAccessRights 权限,PipeOptions 选项,Int32 inBufferSize,Int32 outBufferSize,HandleInheritability 可继承性)[0x00012] 在 /Users/builder/data/lanes/mono-mac-ui-refresh-2 -10/2baeee2f/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/System.Core/System.IO.Pipes /PipeUnix.cs:265 at System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName, PipeDirection 方向, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize,System.IO.Pipes.PipeSecurity pipeSecurity,HandleInheritability 可继承性,PipeAccessRights additionalAccessRights) [0x0004b] 在 /Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baeee2f/source/bockbuild/profiles/mono- 2-10/build-root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/System.Core/System.IO.Pipes/NamedPipeServerStream.cs:100 在 System.IO.Pipes。 NamedPipeServerStream..ctor (System.String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, System.IO.Pipes.PipeSecurity pipeSecurity, HandleInheritability 可继承性) [0x00000] in :0 在 System.IO .Pipes.NamedPipeServerStream..ctor (System.String pipeName, PipeDirection 方向, Int32 maxNumberOfServerInstances,PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, System.IO.Pipes.PipeSecurity pipeSecurity) [0x00000] in :0 at System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize) [0x00000] in :0 at System.IO.Pipes.NamedPipeServerStream..ctor (System.String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstances, PipeTransmissionMode transmissionMode, PipeOptions options) [0x00000] in :0 at (wrapper remoting-invoke-with-check) System.IO.Pipes.NamedPipeServerStream:.ctor (string,System.IO.Pipes.PipeDirection,int,System.IO.Pipes.PipeTransmissionMode,System.IO.Pipes .PipeOptions) 在 ConsoleTestPipeApp1.Program.ListenForPipeServer () [0x00000] 在 /Users/Vadivelu/Project/Service_Test/ConsoleTestPipeApp1/ConsoleTestPipeApp1/Program.cs:21 在 ConsoleTestPipeApp1.Program.Main (System.String[] args) [0x00000] 在/Users/Vadivelu/Project/Service_Test/ConsoleTestPipeApp1/ConsoleTestPipeApp1/Program.cs:16