Object reference not set to an instance of an object” error shows when adding a reference to a WCF service to a Silverlight 4 project


I have a Silverlight enabled WCF service, and a Silverlight 4 project that references it.

The service used to work nicely until I merged some changes another developer made into the service, since then the Silverlight project failed to call the service with "Server not found" error.

I removed the reference to the service, tried to add it again but this failed with error "Object reference not set to an instance of an object".

This is not limited to the above service anymore, this error happens every time I try to add any WCF service to the Silverlight project.

I am using Visual Studio 2010 and the .NET Framework 4.0 for all projects. This problem has happened before and I was able to solve it be creating a new solution, creating fresh projects in it and then adding the code files to the projects one by one. However, this is a nightmare now that my solution contains dozens of projects and hundreds of code files.

anyone out there with a fix for this? I googled this a dozen times and all I got was fixes to similar problems that happened with Silverlight 2 and Visual Studio 2008, but these fixes didn't work for me.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed 👽Commented:
Without seeing the code, it will be difficult to pinpoint. "Object reference not set to an instance of an object" refers to the fact that you are trying to call a method or access a property on an object reference that is null. My suggestion is to debug the code, find the line throwing the error, and determine which object is null.
ChaffeAuthor Commented:
I think this is not a code issue. The code builds correctly and I can reference the service from any other Silverlight project, But not from the project I mentioned above (the one that matters).
kaufmed 👽Commented:
The code builds correctly and I can reference the service from any other Silverlight project
Of course it builds correctly...  null reference pointers are runtime errors, meaning they will not show during compilation, rather they will only appear when the code is actually executed.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ChaffeAuthor Commented:
What I meant to say is that the service is running ok. I can add a reference to it from a different Silverlight project and call the functionality in it successfully.
The error I have happens when I add the reference to the service using Visual Studio 2010 "Add Service Reference" dialoge, so no code is actually being run at that point. As far as I know, when I add a reference to a service, a proxy for that service gets generated in the referencing project. It is in this stage where the error is happening.
kaufmed 👽Commented:
I see. Have you tried running the WSDL file through the WSDL.exe utility? Maybe that would work instead.

You can access this utility by opening up a Visual Studio command prompt (Start->Microsoft Visual Studio 2008->Visual Studio Tools->Command Prompt). In the command window that opens, you can enter:

wsdl.exe /namespace:PickANamespace /out:C:\pick\an\output\filename.cs http://www.example.com/your/wsdl/path.wsdl

The "Add Service Reference" can be finicky at times. So too can WSDL.exe. It may be worth a shot to try it, though.
ChaffeAuthor Commented:
Hi kaufmed,
Thank you for your time, I went with the nightmarish solution and created a fresh solution and added all the code files to it. This solved my problem, but didn't relief my anxiety :(.
This is really annoying, I haven't found why this was hapenning, tried all kinds of stuff, but I had to go with the long and tiresome solution by replacing and creating fresh projects because I knew it worked, and I didn't have enough time to investigate the problem any further.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kaufmed 👽Commented:
Sure. Sorry we weren't able to nail it down  : (
ChaffeAuthor Commented:
had to go with the long and tiresome solution by replacing and creating fresh projects  and I didn't have enough time to investigate the problem any further.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.