1

我们遇到了 WCF 问题,需要很长时间才能诊断出来,所以我将它们发布在这里,以防有人遇到类似问题(在其他任何地方都没有找到参考资料)。

我们的流程经常会因以下未处理的异常而崩溃:

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 更新后出现(并在卸载后消失)。

4

1 回答 1

3

问题原来是IClientChannel

我们忘记在使用后释放通道并Dispose()从终结器线程调用。

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

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

于 2013-05-16T06:50:56.587 回答