Where is mono.unix.native
Mono.Unix.Native
is a namespace. The assembly where it's located is named Mono.Posix.dll
.
I think it's shipped with Mono for Windows - even if it's unlikely to be used there.
How can I use Mono.Unix on Linux?
You need to do what the error message says. Unintuitively, Mono.Unix
lives in Mono.Posix.dll
, so you need to add that as reference.
Get Unix/Linux system architecture using Mono
This may be possible.
There's no way to do this is proper plain Jane .NET, Environment (where'd you expect this to be) doesn't expose it.
But Mono has the Mono.Unix.Native
namespace (you'll need to add a reference to Mono.Posix.dll), which has the Syscall class. This exposes uname
, which may give you what you want; this doesn't seem terribly standard across Linux/Unix versions, and I'm not sure how much normalizing Mono is doing here.
Mono.Unix.Native.Utsname results;
var res = Mono.Unix.Native.Syscall.uname(out results);
if(res != 0)
{
throw new Exception("Syscall failed!");
}
When I run this on my Mac, results.machine
is set to x86_64
. I don't have a Linux machine handy to test for consistency; but this would be the way to do it if there's any at all.
Is it possible to send a unix signal in a Mono C# program?
You are looking for Syscall.kill
in the namespace Mono.Unix.Native
(reference Mono.Posix
).
Example that kills itself with ABRT (6 / abort):
using System;
using Mono.Unix.Native;
namespace killself
{
class MainClass
{
public static void Main(string[] args)
{
var currentPID = Syscall.getpid();
Syscall.kill(currentPID, Signum.SIGABRT);
}
}
}
Ref: http://docs.go-mono.com/?link=M%3aMono.Unix.Native.Syscall.kill
Using UnixSignal in Mono throws System.ArgumentException
SIGTERM
and SIGINT
support was added to Docker in ~2013 (I remember the pull-request because I needed that support in a deployment)
So I'm assuming either SIGQUIT
or SIGHUP
is failing to be installed.
But, since you did not say which signal is returning a IntPtr.Zero
and thus throwing the exception, I would try installing each signal on its own to find the one that is not supported in your Ubuntu Docker environment.
At that point, you can test that signal under a straight C
program to determine if it runs ok as it might be a problem in the Mono
runtime running under Docker.
Plus you can try/catch your UnixSignal.WaitAny
and gracefully degrade your signal processing and write a log message about the offending signal.
Mono application compiled and running on 12.04 not running on 14.04
As it turned out, using nano to view the exception log was my first problem, as it 'hid' the real problem by not wrapping lines, and truncating them with a $.
The real exception was that I was missing libMonoPosixHelper.so, due to LD_LIBRARY_PATH not being added as an Environment Variable.
Unhandled Exception: System.TypeInitializationException:
An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---
System.DllNotFoundException: libMonoPosixHelper.so
See this question for details and the fix.
Related Topics
Update Float Array from C++ Native Plugin
Spawn a New Thread to Open a New Window and Close It from a Different Thread
Use or Clause in Queryover in Nhibernate
Should I Use Return/Continue Statement Instead of If-Else
In C# Wpf, Why Is My Tabcontrol's Selectionchanged Event Firing Too Often
Dynamic Form Generation in Asp.Net
Open iOS Application from Unity
How to Add a Custom View Dynamically to a View in Visual Studio for MAC C#
How to Compare Two Objects in Unit Test
How to Convert Xml to JSON Using C#/Linq
Multiple SQL Statements in One Roundtrip Using Dapper.Net
Entity Framework Specification Pattern Implementation
When Should I Use Out Parameters
C# Call C++ Dll Passing Pointer-To-Pointer Argument
Call C++ Function Pointer from C#
Printing a Formatted HTML Page in C#
ASP.NET Core Disable Authentication in Development Environment