File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -914,7 +914,7 @@ public string ThreadName
914914 /// </para>
915915 /// </remarks>
916916 public string UserName =>
917- m_data . UserName ??= TryGetCurrentUserName ( ) ;
917+ m_data . UserName ??= TryGetCurrentUserName ( ) ?? SystemInfo . NotAvailableText ;
918918
919919 private static string TryGetCurrentUserName ( )
920920 {
@@ -929,8 +929,7 @@ private static string TryGetCurrentUserName()
929929 }
930930 catch ( PlatformNotSupportedException )
931931 {
932- // TODO: on a platform which supports it, invoke `whoami`
933- return SystemInfo . NotAvailableText ;
932+ return Environment . UserName ;
934933 }
935934 catch ( SecurityException )
936935 {
@@ -940,12 +939,15 @@ private static string TryGetCurrentUserName()
940939 declaringType ,
941940 "Security exception while trying to get current windows identity. Error Ignored. Empty user name."
942941 ) ;
943-
944- return SystemInfo . NotAvailableText ;
942+ return null ;
943+ }
944+ catch
945+ {
946+ return null ;
945947 }
946948#endif
947949 }
948-
950+
949951 /// <summary>
950952 /// Gets the identity of the current thread principal.
951953 /// </summary>
You can’t perform that action at this time.
0 commit comments