wpf应用程序中的调用目标抛出了异常 [英] Exception has been thrown by the target of an invocation in wpf application

查看:116
本文介绍了wpf应用程序中的调用目标抛出了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



string ConString = System.Configuration.ConfigurationManager

.ConnectionStrings [ConString]。ToString ();

异常显示:调用目标抛出了异常。



InnerException:{对象引用未设置到一个对象的实例。}

I have written a simple wpf application for binding data in datagrid. It throws error while running at following line.

string ConString = System.Configuration.ConfigurationManager
.ConnectionStrings["ConString"].ToString();
Exception shows: Exception has been thrown by the target of an invocation."

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

推荐答案

.ConnectionStrings [ConString] 似乎是 null

当您在null上使用ToString()时会出现此错误。



检查您是否传递了正确的参数,并且 ConnectionStrings 中有值。


这篇关于wpf应用程序中的调用目标抛出了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆