c# - Electron 用 native C#代码扩展

标签 c# .net electron

我有一个要集成到我的 Electron 项目中的.NET C#组件。我已经使用了edge.js这个库,但是构建该应用程序时显示以下错误

Uncaught Exception:
Error: /var/www/edge-electron/node_modules/electron-edge/build/Release/edge_nativeclr.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEi
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/www/edge-electron/node_modules/electron-edge/lib/edge.js:49:8)

以下是带有edge.js示例代码的 Electron 样板示例代码
const electron = require('electron')
const edge = require('edge')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const url = require('url')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

var helloWorld = edge.func(`
  async (input) => {
    return '.NET Welcomes ' + input.ToString()
  }
`)

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 800, height: 600})

  // and load the index.html of the app.
  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }))

  // Open the DevTools.
  mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })

  // Edge functionality
  mainWindow.on('show', function () {
    // Dereference the window object, usually you would store windows
    console.log('shown')
    helloWorld('JavaScript', function (error, result) {
      if (error) throw error
      console.log(result)
    })
  })
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow()
  }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

关于我将如何解决这个问题的任何想法,还有其他选择吗?任何事物 ?

最佳答案

我有同样的问题。只需使用electron-edge,一切都会正常。

关于c# - Electron 用 native C#代码扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41232501/

相关文章:

c# - 尝试从 .net 应用程序以编程方式访问 Graph REST API 时出现错误 "Unable to check Directory Read access for appId"

c# - Asp.net MVC4, C# 创建对象实例

c++ - 在 .net c++ 中使用 XmlDocument 编写 XML

c# - 本地化 Win7 版本上的 UI 截断

javascript - 当我将鼠标悬停在html按钮上时, Electron 中的单击事件不起作用并且鼠标图标没有更改?

javascript - Electron/JavaScript : Detect when window is un/maximized

c# - 不记录 Console.ReadLine 输出?

C# Razor 静态助手错误 “Collection Was Modified”

c# - LinqKit 嵌套调用 "LINQ to Entities does not recognize the method ' Invoke'"

javascript - 将动态字符串绑定(bind)到 Electron JS 函数