diff options
author | Kenneth Pouncey <kjpou@pt.lu> | 2019-10-25 12:17:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-25 12:17:00 +0300 |
commit | 6ac749ed2099036dc0cfd9dbd9ae9fc22139475d (patch) | |
tree | 62aa2a22d754c1f3ce098eeed108ad5cfed65cc6 /mcs/class/referencesource | |
parent | 9d781eb78ce8cfe79dcc932395e3b72e4e830825 (diff) |
[wasm][bcl] Fix `System.Diagnostics.Trace.TraceError` crash. (#17509)
* Fix `System.Diagnostics.Trace.TraceError` crash.
- WASM does not have access to the command line arguments through the browser so the length is 0 causing index out of range error.
- The zero index of the command line arguments is what decides the `AppName` so under WASM the AppName will be blanks.
* Address review comments
* Remove #ifdef for WASM only.
- Addresses review note.
- As per channel discussion some embedding scenarios might be the same.
Diffstat (limited to 'mcs/class/referencesource')
-rw-r--r-- | mcs/class/referencesource/System/compmod/system/diagnostics/TraceInternal.cs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/mcs/class/referencesource/System/compmod/system/diagnostics/TraceInternal.cs b/mcs/class/referencesource/System/compmod/system/diagnostics/TraceInternal.cs index 1ff316c4c44..9e91d89e988 100644 --- a/mcs/class/referencesource/System/compmod/system/diagnostics/TraceInternal.cs +++ b/mcs/class/referencesource/System/compmod/system/diagnostics/TraceInternal.cs @@ -67,7 +67,12 @@ namespace System.Diagnostics { #if MONO_FEATURE_CAS new EnvironmentPermission(EnvironmentPermissionAccess.Read, "Path").Assert(); #endif - appName = Path.GetFileName(Environment.GetCommandLineArgs()[0]); + // Make sure we have command line arguments before accessing them + // prevents index out of range exception. + // For example Wasm does not have access to command line arguments through browser + var clArgs = Environment.GetCommandLineArgs(); + if (clArgs.Length > 0) + appName = Path.GetFileName(clArgs[0]); } return appName; } |