WCF错误作为对象引用未设置为对象的实例 [英] WCF Error as object reference not set to an instance of an object

查看:83
本文介绍了WCF错误作为对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建WCFService和LINQ时,在此行获取错误对象引用未设置为对象的实例。



getting Error "Object reference not set to an instance of an object" at this line while creating WCFService and LINQ..

base(global::System.Configuration.ConfigurationManager.ConnectionStrings["MySampleDBConnectionString1"].ConnectionString, mappingSource)

推荐答案

最有可能的原因是你的配置文件中没有名为 MySampleDBConnectionString1 的连接字符串。
The likeliest reason is that you don't have a connection string named MySampleDBConnectionString1 in your config file.


那是因为您的任何一个参数都是 null 。对我来说,第二个参数更有可能为null;因为通常你已经填充了ConnectionString属性,或者其中任何一个属性,连接字符串都不可用。



因此,如果您使用的是Visual Studio,请调试在此位置设置断点的代码。然后,一旦您的代码到达此位置,您将看到哪些情况属实;代码中哪个变量为null。然后,您可以(在调用基类的构造函数的特定行之上)将值设置为非null值以最小化此问题。



请记住,WCF也运行在.NET框架上,因此它会抛出的错误很容易像其他所有.NET异常一样处理。 NullReferenceException [ ^ ]是.NET框架的一个例外,初学者总是倾向于它,因为找到哪个对象扔掉它有点棘手,以及抛出它的原因。祝你好运。
That is because either of your parameters are null. For me, the second parameter has a more chance of being null; because usually you've already filled the ConnectionString property, or either of it, the connection string is not available.

So, if you're using Visual Studio, debug the code having a breakpoint set at this position. Then once your code reaches this location, you will see which of the cases is true; which variable is null in your code. Then you can (above that particular line of invoking the base-class's constructor) set the value to a non-null value to minimize this problem.

Remember, WCF also runs over .NET framework, so an error that it would throw would be easily handled as all other .NET exceptions. NullReferenceException[^] is an exception of .NET framework, and beginners always fall for it as it is a bit tricky to find which object threw this, and why it was thrown. Good luck.


这篇关于WCF错误作为对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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