Reputation: 427
I am in the middle of trying to write my first windows service using C# and .NET framework and am having trouble referencing a project within the same solution within the service. My MVC solution structure within VS2012:
Within my service (which I want to fire every x mins) I am referencing methods in the extended processing project that intellisense is able to detect when I am writing code within the service project (I have a using extendedProcessingProject; using webAppProject; and a project references to the extendedProcessingProject and web app project).
The service installs to my local pc without errors. When I start the service I have an error being logged that I cannot seem to figure out:
Exception body: ReminderEmailService Object reference not set to an instance of an object. System.Collections.ListDictionaryInternal
System.NullReferenceException: Object reference not set to an instance of an object.
at ReminderEmailService.ReminderEmailService.ReminderEmails(Object source, ElapsedEventArgs e)
at ReminderEmailService.ReminderEmailService.SendReminderEmails(Object source, ElapsedEventArgs e)
Void SendReminderEmails(System.Object, System.Timers.ElapsedEventArgs)
I know can see though using the System.Diagnostics.Debugger.Launch();
List<SessionReminder> sessions = Queries.GetSessionsToRemind();
//sessions does not have a value, method returns a list of 1
//I suspect this is a project reference issue
debugString += "sessions: \n" + sessions.ToString();
//exception thrown on this line--I suspect because sessions is null
I am using the .NET4.0 (not client profile) on all projects within my solution. Any insight on how to enable my windows service to correctly access these assemblies (webappproject.dll and extendedProcessing.dll) would be much appreciated, as these dll's are being installed by install shield.
Upvotes: 0
Views: 2115
Reputation: 6864
The exception you've displayed doesn't look like an issue with referencing assemblies. It looks like a plain ordinary bug in the code, not a missing assembly.
I always create a test harness for a windows service to enable me to run the service as a simple Windows Forms application to make debugging easy.
Separate your service implementation into a separate assembly from the assembly with the actual windows service. Create another project WPF/Winforms with a simple start/stop button. From both the windows service and winforms application reference the assembly containing the functionality that runs within your service.
Upvotes: 1
Reputation: 182
It might not be an actual assembly reference issue. The error you are seeing is that the runtime is complaining about accessing methods/fields/properties of a null object. This indicates that your code is accessing an uninitialized object.
Upvotes: 1