Link to home
Start Free TrialLog in
Avatar of Chaffe
ChaffeFlag for Afghanistan

asked on

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

Hi,

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.

Thanks.
Avatar of kaufmed
kaufmed
Flag of United States of America image

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.
Avatar of Chaffe

ASKER

Kaufmed,
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).
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.
Avatar of Chaffe

ASKER

Kaufmed,
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Chaffe
Chaffe
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sure. Sorry we weren't able to nail it down  : (
Avatar of Chaffe

ASKER

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.