c# - 使用 Mono 的 Chrome native 消息传递

标签 c# mono chrome-native-messaging

我实际上是在尝试使用 Chrome Native Messaging 在 OSX 中启动我的 C# mono 可执行文件。

到目前为止,我从未能够使用 OSX 启动可执行文件(它在 Windows 上运行良好)

这是 native 消息传递主机的 list :

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

这是 launch.sh 文件:

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

我经常收到以下错误:

"Native host has exited."

我尝试启动 sh 文件,它似乎运行良好(它读取标准输入中的条目)

1/这种方法是否可行,我遗漏了什么? 2/是否有另一种使用 Mono 启动可执行文件的方法? (我尝试直接将可执行路径放在 list 上,但它也不起作用 3/如果我使用 Mono(python/C++)以外的东西,我将不得不重新编写我的可执行文件,这可能会花费很多。

最佳答案

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

是的,它应该可以工作。我已经看到与 JAVA 运行时非常相似的设置,但我看不出有任何理由不能与 MONO 运行时一起使用。

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

我强烈建议尽可能使用绝对路径:

/absolute_path_to/mono/absolute_path_to/my_executable.exe

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

没有。 native 消息传递适用于任何可执行文件,无论用于创建它的编程语言如何。


顺便说一句:当您的可执行文件抛出您的代码未处理的异常但您的 launch.sh 脚本将“吞下”错误消息时,Mono 可能无法启动。您可能应该像这样将 STDERR 重定向到日志文件:

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

如果 STDERR 没有提供有用的信息,您也可以尝试重定向 STDOUT(我知道本地消息传递需要它,但您正在调试问题,对吧?)这个:

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

无论如何,如果您还没有为您的应用程序添加日志记录功能,您应该这样做。

关于c# - 使用 Mono 的 Chrome native 消息传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213042/

相关文章:

c# - 将 Sphero 2.0 连接到 Mac OSX 10.9

c# - 如何将多行文本框作为一行保存到文本文件中?

asp.net - 在 Linux 上使用 xsp 运行 ASP.NET 应用程序时缺少方法错误

c# - Chrome 原生消息

c++ - 如何从 Chrome 扩展程序向 native 应用程序发送消息?

c# - Const 与 protected 静态只读

C#:有什么方法可以绕过完全限定路径的 260 个字符限制?

c# - 如何从多线程访问 GUI (GTK)?

c# - 单声道 GTK# : Trying to remove text in ComboBox and then prepend new text to the ComboBox but some of the old text remains

Windows Chrome 扩展 native 消息只能收到第一个响应