Solved

C# Windows Service Woes

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What are the big features of MVC5? 4 50
import issue in bit values 3 44
Problem with SqlConnection 5 109
Achieve json result 2 28
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now