为 WCF 服务添加服务引用时出现 VS 2010 错误“对象引用未设置为对象的实例" [英] VS 2010 Error “Object reference not set to an instance of an object” when adding Service Reference for WCF Service

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

问题描述

我有一个 VS2010 (RTM) 解决方案,其中包含:

I have a VS2010 (RTM) solution which contains:

WCF 服务项目
控制台 WCF 客户端项目
DataContracts 和成员的类项目
一些简单类的类项目

WCF Service project
Console WCF client project
Class project for DataContracts and members
Class project for some simple classes

我在控制台客户端项目中成功添加了服务引用并运行了客户端.然后我做了一个很长的开发周期,反复修改服务,然后更新控制台服务引用.然后,我使用引用和 app.config 更改了项目的命名空间和程序集名称以及 .cs.我当然错过了一些东西,因为它不会构建,所以我最终删除了项目引用和服务引用,清理并成功构建.

I successfully added a service reference in the console client project and ran the client. I then did a long dev cycle repeatedly modifying the service then updating console service reference. I then changed the namespace and assembly names for the projects as well as the .cs using references and app.config. I of course missed some things as it would not build so I eventually removed the project references and the service reference, cleaned and built successfully.

然后我尝试再次添加服务引用,它发现了它,但在 OK'ing 时抛出了未将对象引用设置为对象的实例".修复下面的答案...

I then attempted to add the service reference again, it discovered it but threw the "Object reference not set to an instance of an object" when OK'ing. Fix in answer below...

推荐答案

发布我自己的修复,因为我在别处找不到它:

Posting my own fix as I couldn't find it elsewhere:

Stackoverflow'ing/Googling 没有找到任何地方,所以我最终在记事本中打开了解决方案文件,发现引用我的控制台项目的条目对 WCF 服务项目具有项目依赖性.

Stackoverflow'ing/Googling didn't get me anywhere so I eventually opened the solution file in notepad and found that the entry referencing my console project had a project dependency on the WCF Service project.

删除该 ProjectSection 后,我能够添加服务引用并重新开始工作.

After I removed that ProjectSection, I was able to add the service reference and was back in business.

在尝试重现问题时,将服务引用添加到项目会添加服务项目依赖项,但删除服务引用不会.我认为更改命名空间是导致找不到依赖项引用的罪魁祸首?

In trying to reproduce the problem, adding the service reference to the project adds the service project dependency but removing the service reference does not. I presume changing the namespace was the culprit with it not finding the dependency reference?

这篇关于为 WCF 服务添加服务引用时出现 VS 2010 错误“对象引用未设置为对象的实例"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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