Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# Windows Service Woes

Posted on 2004-08-16
8
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

610 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