0

During debugging of WCF in vs2012 it throws the below exception;

I am using Vs2012 IIS7.5 and Windows7. The service is hosted on iis.

"Object reference not set to an instance of an object."

How can i debug WCF service?

John Saunders
  • 157,405
  • 24
  • 229
  • 388
MindFresher
  • 700
  • 4
  • 12
  • 25
  • Almost all cases of NullReferenceException are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Dec 04 '12 at 08:46

2 Answers2

1

Try adding below line to the code.

System.Diagnostics.Debugger.Launch();

and start debugging when asked.

Damitha
  • 371
  • 3
  • 13
0

Go to the "Attach to Process" dialog and attach to the IIS worker process (w3wp.exe). Go to the "Exceptions" dialog and tell it to throw on all exceptions. Then, if an exception occurs, it will break into the debugger at that point.

I also recommend that you consider catching exceptions that occur within the service and log them to the event log, with as much diagnostic data as you can. In my experience, I can usually identify the cause purely by looking at the exception stack trace. If I can do that then I don't have to waste time debugging. Have a look at the [ExceptionShielding] attribute from the Enterprise Library for an easy way to add error logging to all your service methods.

Christian Hayter
  • 29,333
  • 6
  • 65
  • 96