Ascertain reason for Channel Fault in WCF+NamedPipes

痴心易碎 提交于 2020-03-31 18:00:54

问题


I have a whole sequence of interlinked questions. I would like to know answers for all of them independantly, so *yes*, some of them appear to be X-Y questions; but I do want to know the solution to them anyway!. See end of question for list of other questions in this set.


How do I determine the reason for a Channel Fault, e.g. caused by closing the exe on one end of a DuplexChannel connected by named pipes?

I have two exes running; communicating over named pipes, via WCF. (If it's relevant, one is installed as a WindowsService, the other is a WinForms UI exe, started by the user.)

When I kill the UI exe (in TaskManager, for example) I see that in the Service exe on the other end of the pipe I trigger the event handler: ((ICommunicationObject)(OperationContext.Current.Channel)).Faulted.

If I debug into that with VisualStudio, I can see that there's been the following Exception thrown:

System.ServiceModel.CommunicationException: There was an error reading from the pipe: Unrecognized error 109 (0x6d).
    ---> System.IO.PipeException: There was an error reading from the pipe: Unrecognized error 109 (0x6d).
   at System.ServiceModel.Channels.PipeConnection.OnAsyncReadComplete(Boolean haveResult, Int32 error, Int32 numBytes)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.TransportDuplexSessionChannel.EndReceive(IAsyncResult result)
   at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)

But I can only see that from the magic $exception variable. Nothing else in the programmatic context appears to know why the Channel Fault happened

As discussed over here: Access Visual Studio's $exception variable that $exception isn't inherently accessible, in the general case.

Is there any way for me to arrange that logging code can determine why the Channel Faulted?

Any StaticAccessors for the Channel?

Any alternative EventHandlers to register to?

Is there anything I can do to set up useful logging, outside of an attached VisualStudio debugger?


Other questions in this problem set.
  • C#: How do I prevent a pipe reading error, when closing the exe on one end of a DuplexChannel connected by Named Pipes?
  • Ascertain reason for Channel Fault in WCF+NamedPipes
  • Is using the `Marshal` static class in otherwise normal C# code unwise?
  • Is there a way to predict that `Marshal.GetExceptionForHR(code, pointers)` would throw an `AccessViolationException`
  • Is this a suitable use of `HandleProcessCorruptedStateExceptions`

来源:https://stackoverflow.com/questions/60424741/ascertain-reason-for-channel-fault-in-wcfnamedpipes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!