Solved

C# Windows Service Woes

Posted on 2004-08-16
8
158 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WKHTMLTOPDF - --disable-smart-shrinking not working 10 88
C#.NET and microsoft certification. 3 40
Google Directions API to Map URL -C#? 3 25
C# bracket error 3 31
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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