首页 > 解决方案 > 单测试安装失败并出现 System.NullReferenceException

问题描述

我在 debian(Linux 5.7.0-1-amd64 #1 SMP Debian 5.7.6-1 (2020-06-24) x86_64 GNU/Linux)上,最近安装了 Mono 框架(sudo apt-get install mono-devel)。

mono --version给我

Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3 Wed Apr  8 15:33:36 UTC 2020)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          supported, not enabled.
    Suspend:       hybrid
    GC:            sgen (concurrent by default)

然后,我尝试运行mono-test-install

Active Mono: /usr/bin/mono
Other Mono executables: /bin/mono 

You have a working System.Drawing setup

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at Program.Main () [0x00016] in <70d3c907c7f1453aa373f2b3e2a3a38a>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at Program.Main () [0x00016] in <70d3c907c7f1453aa373f2b3e2a3a38a>:0

在生成的源文件中,有如下代码:

using System;
using System.Reflection;
using System.IO;

class Program {

    public static void Main()
    {
        object watcher = new FileSystemWatcher()
            .GetType ()
            .GetField ("watcher", BindingFlags.NonPublic | BindingFlags.Static)
            .GetValue (null); //Here it fails
        
        Console.WriteLine ("Your file system watcher is: {0}",
                   watcher != null
                   ? watcher.GetType ().FullName
                   : "unknown");
    }
}

我应该担心吗?

标签: c#linuxmono

解决方案


推荐阅读