Solved

C# Windows Service Woes

Posted on 2004-08-16
8
159 Views
Last Modified: 2011-04-14
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#!
0
Comment
Question by:Anastasia74
  • 3
  • 2
8 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 11807775
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.
0
 

Author Comment

by:Anastasia74
ID: 11816406
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!
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 100 total points
ID: 11817976
Did you create the DLL or is it a standard/third party one? If it is yours, you can add its project to your service solution and then step freely into it. Also have a look at the variables that are around the code which calls the DLL - maybe the problem is there (especially if the DLL is not a .Net one). I am running several services as windows applications and vica versa, so this is not a problem in general.
0
 

Author Comment

by:Anastasia74
ID: 11818142
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 -> http://www.experts-exchange.com/Community_Support/Q_21096266.html

Thanks.
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 11818153
No problem. I'm glad you fixed it. Good luck
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question