实例化行调用new时的NullReferenceException

0 c#

static void Main()
{
    AppHelper helper = new AppHelper();
    // more stuff
}
Run Code Online (Sandbox Code Playgroud)

上面使用csc.exe进行编译,但在运行时抛出NullReferenceException:未处理的异常:System.NullReferenceException:对象引用未设置为对象的实例.在AppHelper..ctor()

public class AppHelper
{
    private string connect = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString();

    public AppHelper()
    {
        // TODO
    }
}
Run Code Online (Sandbox Code Playgroud)

调试器从app.config中找到connectionString但运行可执行的choke.

SLa*_*aks 6

您有AppHelper构造函数中的代码使用null引用的内联字段初始值设定项.

如果您在调试器中运行代码,它会在哪里中断?