2013-05-16 25 views
1

我们遇到了WCF的问题,这让我们花了很长时间来诊断,所以我在这里发布它们以防有人遇到类似问题(没有在其他地方找到引用)。WCF终结器中的NullReferenceException

我们的流程往往会与下面的未处理的异常崩溃:

System.NullReferenceException: Object reference not set to an instance of an object. 
at System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 

System.NullReferenceException: Object reference not set to an instance of an object. 
at System.Threading.Overlapped.Free(NativeOverlapped* nativeOverlappedPtr) 
at System.ServiceModel.Channels.OverlappedContext.Free() 
at System.ServiceModel.Channels.OverlappedContext.FreeOrDefer() 
at System.ServiceModel.Channels.SocketConnection.Abort(TraceEventType traceEventType, String timeoutErrorString, TransferOperation transferOperation) 
at System.ServiceModel.Channels.CommunicationPool`2.EndpointConnectionPool.CloseIdleConnection(TItem connection, TimeSpan timeout) 
at System.ServiceModel.Channels.IdlingCommunicationPool`2.IdleTimeoutEndpointConnectionPool.IdleTimeoutIdleConnectionPool.OnIdle() 
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 

System.NullReferenceException: Object reference not set to an instance of an object. 
at System.Threading.Overlapped.Free(NativeOverlapped* nativeOverlappedPtr) 
at System.Net.AsyncRequestContext.Dispose(Boolean disposing) 
at System.Net.RequestContextBase.Finalize() 

异常通常发生几个小时盯着过程后,有时几分钟后。

奇怪的是,他们只会在安装2013年1月Windows更新(并卸载它们后离开)后才会显示。

回答

3

问题原来是IClientChannel

我们忘记了使用后的通道,并从终结器线程调用Dispose()

我的猜测是IClientChannel使用的非托管资源必须从创建它们的同一个线程中释放。

从同一个线程调用Dispose()后问题就消失了。