<p>I have a windows service that runs various system monitoring operations.  However, when running <code>SNMP</code> related checks, I always get a <code>NullReference exception</code>.  </p>

<p>The code runs fine when run through the user interface (under my username and password), but always errors running as the service.  </p>

<p>I've tried running the service as different user accounts (including mine), with no luck.  I've tried replacing the <code>SNMP</code> monitoring code with calling the <code>PowerShell cmdlet get-snmp</code> (from the <code>/n NetCmdlets</code>), but that yields the same error.</p>

<p>The application I'm working with is <a href="http://codeplex.com/polymon" rel="nofollow noreferrer">PolyMon</a>.  </p>

<p>Any ideas?</p>

[{'answer_id': 48584, 'author': 'David Schmitt', 'author_id': 4918, 'author_profile': 'https://Stackoverflow.com/users/4918', 'pm_score': 2, 'selected': False, 'text': "<p>You can attach a debugger to the running process before triggering the exception. This should give you a better idea what's up with the application.</p>\n"}, {'answer_id': 48615, 'author': 'Chris Kimpton', 'author_id': 48310, 'author_profile': 'https://Stackoverflow.com/users/48310', 'pm_score': 1, 'selected': False, 'text': "<p>A couple of things we've seen - more about differences between interactive vs services, but might help...</p>\n\n<p>One thing we've seen that does not seem relevant is the difference with what is on the user vs system path. </p>\n\n<p>Another thing we've seen relates to temporary files - the service we had was creating lots in the windows\\temp directory - we tracked this down when it had created something like 65000 of these files and thus hit the limit of what a directory can hold...</p>\n\n<p>Regards,\nChris</p>\n"}, {'answer_id': 48623, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 3, 'selected': True, 'text': "<p>Some ways to debug:</p>\n\n<ul>\n<li>Is there any additional information in the Windows events log?</li>\n<li>I believe you should be able to listen to some kind of global-exception event like Application_Exception in windows services. I can't remember the exact name but you can atelast dump stack trace from there.</li>\n<li>You should be able to start debugging the project in service mode.</li>\n</ul>\n\n<p>Some code snippets/stack trace/information will definitely help.</p>\n"}, {'answer_id': 72942, 'author': 'Jay', 'author_id': 12479, 'author_profile': 'https://Stackoverflow.com/users/12479', 'pm_score': 1, 'selected': False, 'text': "<p>I have tackled these kind of issues before, if you haven't already found the answer, I suggest the following:</p>\n\n<ul>\n<li>Enable tracing/logging in all third party apps and libraries you are using such that the errors are logged to files instead of stdout or stderr. Often times, you will find a clue from these.</li>\n<li>Your Windows Service may be relying on some Windows networking set up to be in place before startup. This, can be due to environment (PATH, as others have suggested) or due to 'dependencies' on other services. </li>\n</ul>\n\n<p>Jay.........</p>\n"}]
['https://Stackoverflow.com/questions/48574', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1233/']