2
votes

I'm actually trying to launch my C# mono executable in OSX with Chrome Native Messaging.

So far, I've never been able to launch the executable with OSX (it works well on Windows)

Here's the manifest of the native messaging host :

{
   "allowed_origins" : 
    [ 
        "chrome-extension://njbimgehbcecolchhhfpamfobkedoein/"
    ],
   "description" : "test native messaging host",
   "name" : "com.myapp.native.host",
   "path" : "/Applications/myapp/launch.sh",
   "type" : "stdio"
}

Here's the launch.sh file :

#!/bin/bash
/usr/local/bin/mono --runtime=v4.0.30319 my_executable.exe "$@"

I constantly get the following error :

"Native host has exited."

I tried to launch the sh file and it seems to work well (it reads entries in stdin)

1/ Is this method likely to work, and I'm missing something ? 2/ Is there another way to launch an executable using Mono ? (I tried putting directly the executable path on the manifest but it also doesn't work 3/ Should I use something else than Mono (python / C++), I would have to rework my executable and it could cost a lot.

1

1 Answers

1
votes

1/ Is this method likely to work, and I'm missing something

Yes it should work. I've seen very similar setup with JAVA runtime and I don't see any reason why it should not work with MONO runtime.

2/ Is there another way to launch an executable using Mono ?

I definitely recommend using absolute paths everywhere you can:

/absolute_path_to/mono /absolute_path_to/my_executable.exe

3/ Should I use something else than Mono (python / C++)

No. Native messaging works with any executable regardless of programming language used to create it.


BTW: Mono can fail to start when your executable throws exception which is not handled by your code but your launch.sh script will "swallow" error message. You should probably redirect STDERR to log file like this:

#!/bin/bash
/absolute_path_to/mono --runtime=v4.0.30319 /absolute_path_to/my_executable.exe "$@" 2> /absolute_path_to/my_executable.log

If STDERR does not provide useful information you can try to redirect also STDOUT (I know it is needed for Native messaging but you are debugging the problem right?) like this:

#!/bin/bash
/absolute_path_to/mono --runtime=v4.0.30319 /absolute_path_to/my_executable.exe "$@" > /absolute_path_to/my_executable.log 2>&1

Anyway you should add logging capabilities to your application if you have not already done that.