Windows service NullReferenceException

M

mdhaman

hi,

I have a windows service written in VB.Net and framework 2.0. It is a
multithread service and it is using threadpool to manage threads.

Recently I have started getting NullReferenceException and after that
windows service crashes.

System.Transactions Critical: 0 : <TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled
exception</Description><AppDomain>PublishingServiceTestApp.vshost.exe</AppDomain><Exception><ExceptionType>System.NullReferenceException,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Object reference not
set to an instance of an object.</Message><StackTrace> at
System.Threading.Overlapped.Free(NativeOverlapped* nativeOverlappedPtr)
at System.Net.Sockets.OverlappedCache.InternalFree()
at
System.Net.Sockets.OverlappedCache.InterlockedFree(OverlappedCache&amp;amp;
overlappedCache)
at
System.Net.Sockets.BaseOverlappedAsyncResult.ForceReleaseUnmanagedStructures()
at System.Net.Sockets.BaseOverlappedAsyncResult.Cleanup()
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result,
IntPtr userToken)
at
System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped*
pOVERLAP)</StackTrace><ExceptionString>System.NullReferenceException: Object
reference not set to an instance of an object.
at System.Threading.Overlapped.Free(NativeOverlapped*
nativeOverlappedPtr)
at System.Net.Sockets.OverlappedCache.InternalFree()
at
System.Net.Sockets.OverlappedCache.InterlockedFree(OverlappedCache&amp;amp;
overlappedCache)
at
System.Net.Sockets.BaseOverlappedAsyncResult.ForceReleaseUnmanagedStructures()
at System.Net.Sockets.BaseOverlappedAsyncResult.Cleanup()
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result,
IntPtr userToken)
at
System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped*
pOVERLAP)</ExceptionString></Exception></TraceRecord>

Can anyone help me to identify the problem?
 
M

Mr. Arnold

mdhaman said:
hi,

I have a windows service written in VB.Net and framework 2.0. It is a
multithread service and it is using threadpool to manage threads.

Recently I have started getting NullReferenceException and after that
windows service crashes.


Can anyone help me to identify the problem?

The NullReferenceException means a reference to an object has not been
instantiated/set or has been destroyed when the code referencing the object
wanted to use the object.

It could be that the Garbage Collector came along and destroyed the object
at one point, which could be a problem if the object is only instantiated
one time, or somehow, the code has taken a path to not instantiate the
object, if you are manually destroying objects.

IMHO, the best way you're going to be able to pin point what area of the
program it's going down in is doing Try/Catches in your routines and on the
Catch, dump the Ex.Message and ex.Stacktrace to the Eventlog or to a text
file if you like, which the Stacktrace will at least give you the name of
the routine it's going down in.

Then you can look at the objects in that area and make a determination as to
what object could be setting at a Null value when the code wants to use the
object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top