microsoft / vs-pty.net

Fork pseudoterminals in C#
MIT License
49 stars 18 forks source link

mono support #18

Closed bnuzhouwei closed 3 years ago

bnuzhouwei commented 4 years ago

System.Native is not available in .NET and mono, how to make it usable for mono?

Unhandled Exception:
System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00014] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x00142] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x00091] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Spawn (Pty.Net.PtyOptions options, System.Int32 timeout) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Terminal (System.String name, System.Int32 cols, System.Int32 rows) [0x00060] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at ConsoleApp1.Program.Main (System.String[] args) [0x00001] in <2f412f014020491a96a31603e2a7fcf1>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00014] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x00142] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x00091] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Spawn (Pty.Net.PtyOptions options, System.Int32 timeout) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Terminal (System.String name, System.Int32 cols, System.Int32 rows) [0x00060] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at ConsoleApp1.Program.Main (System.String[] args) [0x00001] in <2f412f014020491a96a31603e2a7fcf1>:0 
javierdlg commented 3 years ago

I'm not sure I understand the question. Are you attempting to build and getting that exception? This project is cross-compat so it should work on linux using mono. Nevertheless, I'd suggest using netcore instead since it adopted mono :)

javierdlg commented 3 years ago

Closing due to no response.

bnuzhouwei commented 1 year ago

The error still exits in Mono:

import clr, System
from Pty.Net import *
class Pty:
    def __init__(self, name, cols=180, rows=500):
        self.name = name
        self.started = ph.dd.now()
        self.host = "127.0.0.1"
        self.cols = cols
        self.rows = rows
        app = "/bin/bash"
        options = PtyOptions()
        options.Name = name
        options.Cols = 180
        options.Rows = 500
        options.Cwd = "/root"
        options.App = app
        self.pty = PtyProvider.SpawnAsync(options, System.Threading.CancellationToken()).GetAwaiter().GetResult()
pty = Pty("lo")
System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0006a] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00012] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x0011f] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x0007b] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper delegate-invoke) 
RHamers commented 10 months ago

I have the same error on Ubuntu 22.04 and mono. On windows it works fine. Any input about what could be wrong? :)