Sử dụng ILSpy, bạn có thể nhìn vào một phiên bản de-biên dịch của GetCurrent
và GetCurrentInternal
, mà GetCurrent
cuộc gọi . Kết quả là:
GetCurrent:
public static WindowsIdentity GetCurrent()
{
return WindowsIdentity.GetCurrentInternal(TokenAccessLevels.MaximumAllowed, false);
}
GetCurrentInternal:
internal static WindowsIdentity GetCurrentInternal(TokenAccessLevels desiredAccess, bool threadOnly)
{
int errorCode = 0;
bool flag;
SafeTokenHandle currentToken = WindowsIdentity.GetCurrentToken(desiredAccess, threadOnly, out flag, out errorCode);
if (currentToken != null && !currentToken.IsInvalid)
{
WindowsIdentity windowsIdentity = new WindowsIdentity();
windowsIdentity.m_safeTokenHandle.Dispose();
windowsIdentity.m_safeTokenHandle = currentToken;
return windowsIdentity;
}
if (threadOnly && !flag)
{
return null;
}
throw new SecurityException(Win32Native.GetMessage(errorCode));
}
Kể từ threadOnly
phải lúc nào cũng sai khi gọi từ GetCurrent
, và currentToken
phải có giá trị cho người khác return statement, tôi không nghĩ rằng bạn có nguy cơ bị null WindowsIdentity
.
tốt, tôi googled nó cho bạn :) Điều này có vẻ là người bạn nhỏ của chúng tôi: http://youtrack.jetbrains.com/issue/RSRP-328266 – Noich
Chính xác.Các chú thích ở trên được cho là sửa chữa 328266 (do đó nhận xét trên dòng đầu tiên của đoạn mã XML), nhưng vì bất kỳ lý do nào, sửa chữa dường như không hoạt động. Nếu điều này cho thấy sự cố trong cài đặt hoặc cấu hình R # của tôi, vui lòng giải thích. –
Tôi thực sự không có ý tưởng :) Bạn sẽ phải mang nó với QA của họ. – Noich