Link to home
Start Free TrialLog in
Avatar of Anastasia74
Anastasia74

asked on

C# Windows Service Woes

Hi,

I have created a C# windows service from what was previously a C# Windows app.  For some reason, I'm finding that function calls to a dll work fine when called from the app, but fail when called from the service.  

The error it gives from the service is System.NullReferenceException: Object reference not set to an instance of an object.  I don't understand why it would be different just because it's now being run as a service.  

It would help if I could get it to step into the dll, but that only seems to happen when running as the windows app.

Any ideas??  

P.S.  Very new to C#!
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

When you start the service, you can go in VS,select Debug->Processes. If needed select the checkbox Show system processes. Then you can select the service process and attach to it. Then you are in debug mode for the service and you can step over it as if it is a windows application, so you can try debugging your problem. This does not work however if the code that is making problems is a part of the start procedure of the service (because you cannot attach to the process so fast to debug the start procedure). But you can put a first line in the start procedure for the service to be a sleep fo 15 seconds, during which you can attach to the service and then debug even the start procedure.
Avatar of Anastasia74
Anastasia74

ASKER

Thanks for the reply.  

I have been able to get as far as placing the service in debug mode and can step through it OK.  My problem is that when it comes to the line (in the service code) that is causing the error, it is a call to a DLL function, and the debugger doesn't step _into_ the DLL.  So I can't determine where the error is really coming from.

My second problem is that the code in the service is identical to that in the windows app - so why it fails in the service when it works otherwise has me stumped.  But if I could solve problem 1 and step into the DLL, I will (hopefully) be able to figure problem 2 out!
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland 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
I figured it out myself - the DLL was doing weird things (not third party, not mine, someone else's).  Trying to get you some points for trying to help -> https://www.experts-exchange.com/questions/21096266/21-Aug-Q-21094801.html

Thanks.
No problem. I'm glad you fixed it. Good luck