我从我的一位用户那里收到了一个 Event Viever 条目,说发生了未经授权的访问异常。该过程从作为 SYSTEM 的服务启动。我能够将错误缩小到创建 NamedPipeServerStream 的部分:
// <error in this block>
PipeSecurity pipeSa = new PipeSecurity();
pipeSa.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
NamedPipeServerStream np = new NamedPipeServerStream("streamname", PipeDirection.InOut,1,PipeTransmissionMode.Message,PipeOptions.None,16383,1, pipeSa);
// </error in this block>
while (true){
try{
if (!np.IsConnected)
np.WaitForConnection();
}catch(Exception e){
}
}
我很确定错误在上面的 3 行块中。它不会发生在我的任何计算机上,所以我不能重复错误。上述代码中的哪些内容不被视为最佳实践并且可能导致错误?
错误信息图片: