wpf 应用程序中调用的目标引发异常

本文关键字:异常 目标 应用程序 调用 wpf | 更新日期: 2023-09-27 18:36:04

我编写了一个简单的 wpf 应用程序,用于在 datagrid 中绑定数据。它在以下行运行时引发错误。

string ConString = System.Configuration.ConfigurationManager
                         .ConnectionStrings["ConString"].ToString();

异常显示:Exception has been thrown by the target of an invocation."

InnerException:{"Object reference not set to an instance of an object."}

wpf 应用程序中调用的目标引发异常

可能 System.Configuration.ConfigurationManager.ConnectionStrings["ConString"] 为 NULL 或System.Configuration.ConfigurationManager.ConnectionString 为 NULL。