【问题标题】:System.NullReferenceException in Linux Mono using Fast Colored Text Box使用快速彩色文本框的 Linux Mono 中的 System.NullReferenceException
【发布时间】:2023-03-21 05:01:02
【问题描述】:

我正在 WinForms 中创建一个小型 GUI,目前正在实现语法高亮。我发现了一个在 Windows 中运行良好并提供 dll 供使用的库。但是,该库似乎总是在 Linux 中崩溃。这是我得到的错误:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
  at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
  at FDE.FGUI.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
  at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
  at FDE.FGUI.Main () [0x00000] in <filename unknown>:0 

从错误消息来看,Mono 似乎没有看到在构造函数期间出现&lt;filename unknown&gt; 错误的 dll。不可否认,我使用的图书馆 (FastColoredTextBox) 没有通过 MoMA,因为它有相当数量的 P/Invokes。但是,有些人似乎说他们能够通过避免冲突的方法来运行它。

这是关键。我决定尝试通过 WINE 运行 GUI 并完全绕过 Mono。由于它在 Windows 上运行良好,我认为这可以修复错误。但是,在 Wine 中会弹出完全相同的错误消息。我什至在 Windows 和我的 Ubuntu live 机器之间有一个共享文件夹。完全相同的可执行文件将在完美的 Windows 上运行,但在 Linux 中会因此错误而崩溃。在这一点上,经过数小时的研究,我被难住了。

是否有某种方式必须在 Mono 中加载 dll,或者错误在于 Mono/Wine 与 WinForms 不兼容?

【问题讨论】:

    标签: c# linux winforms mono wine


    【解决方案1】:

    我看了source到图书馆。假设我找到了正确的库,它会调用 Win32 API,这在现有的 Mono 上是行不通的。

    在 Wine 下运行应该工作得更好,但 Wine 只是部分实现了 Win32 API。

    您可能需要找到一个跨平台的替代品。

    【讨论】:

    • 这就解释了。奇怪的是它们似乎都没有在构造函数中,但这就是它崩溃的地方。相信我,我想转向更跨平台的东西。但是,我的老板喜欢 C# WinForms 的外观,尤其是因为我们的大多数客户都可以使用 Windows。我只是想让我们的代码更具前瞻性。
    • 我并没有试图找出导致错误的确切原因,但是使用了一些返回 IntPtr 的 API 调用。如果失败的 API 调用返回 null,那么这将导致您看到的问题。
    • 是的,这听起来很对。我现在似乎找到了替代方案。它没有那么特色,但它应该运行。感谢您的帮助!
    猜你喜欢
    • 2023-03-04
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    相关资源
    最近更新 更多