开发者

VS 2010 Error “Object reference not set to an instance of an object” when adding Service Reference for WCF Service

开发者 https://www.devze.com 2022-12-28 07:54 出处:网络
I have a VS2010 (RTM) solution which contains: WCF Service project Console WCF client project Class project for DataContracts and members

I have a VS2010 (RTM) solution which contains:

WCF Service project

Console WCF client project

Class project for DataContracts and members

Class project for some simple classes

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 an开发者_JAVA百科d built successfully.

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...


This problem will be observed if you try to add a service reference to a project, but there is an existing service reference in the same project, to another project that you have unloaded. For example, you can use the following steps to reproduce:

  1. Create two separate WCF service projects, Service1 and Service2
  2. Create a Client project and add a service reference to a service in the Service1 project
  3. Unload the Service1 project
  4. In the client project, try to add a reference to a service in the Service2 project - you will get the above error

Although this shouldn't happen since the services are independent, the fix is to reload the Service1 project while you add the reference to Service2.


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

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.

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?


There is an existing project dependency between the service and the client. Right Click on Consumer Project -> Project Dependencies; Uncheck the dependency between the Consumer and Service. (This will remove any internal objects or references from the consumer)

Retry: Add service reference.


To anyone having this problem and not helped with the above approaches : See if the UI portion has some data bindings (in my case it was a datagrid control on a silverlight client) ymmv Also, if you are having a service client, then the bindings in this form probably may come in the form of _Completed method, have a closer look into it to see if you are missing some data/parameters that ought to be there. hth


Uninstall all versions of silver light SDKs (Silverlight, Silverlight3, etc) and Silverlight tools from the "Add/Remove Programs". Reinstall the Silverlight-tools, that should fix the issue.


Remove and re-add the service reference. Simple yet worked for me.

What caused the "object reference" error was simply changing the service reference endpoint url from local to my dev server. Never had this problem before except for this one time.


My Problem in vs17 (Object reference not set to an instance of an object):

So, I had renamed the Project in vs2015, but that didn't rename the folder that the project was in. When I opened it up in vs2017 and tried to ad a WCF Service, after clicking OK I would get object ref not found.

My Fix:

So, I unloaded the project file from the solution and renamed the project folder to match the project file, reloaded the project into my solution in vs2017, now I am able to "Add WCF Service"!

0

精彩评论

暂无评论...
验证码 换一张
取 消