Skip to content

Bad Process.StartTime in .NET 6 on Android #67583

Closed
@AigioL

Description

@AigioL

Description

System.Diagnostics.Process.StartTime throws an exception on net6.0-android, but works fine on Xamarin.Android

Reproduction Steps

https://github.com/BeyondDimension/AspNetCore.Mobile/blob/refs/tags/test-process-starttime/src/AspNetCore.Mobile.Droid/MainActivity.cs#L50-L63

void TestProcessStartTime()
{
    string startTimeString;
    try
    {
        var p = global::System.Diagnostics.Process.GetCurrentProcess();
        startTimeString = p.StartTime.ToString();
    }
    catch (Exception e)
    {
        startTimeString = e.ToString();
    }
    WriteLine($"StartTime: {startTimeString}");
}

Expected behavior

Returns the correct DateTime

Screenshot_1649162413

Actual behavior

 android.runtime.JavaProxyThrowable: System.UnauthorizedAccessException: Access to the path '/proc/stat' is denied.
     ---> System.IO.IOException: Permission denied
       --- End of inner exception stack trace ---
        at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
        at Interop.CheckIo(Error error, String path, Boolean isDirectory, Func`2 errorRewriter)
        at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
        at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
        at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
        at System.IO.Strategies.UnixFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
        at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
        at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
        at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
        at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
        at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
        at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
        at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
        at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
        at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
        at System.IO.File.InternalReadAllText(String path, Encoding encoding)
        at System.IO.File.ReadAllText(String path)
        at System.Diagnostics.Process.get_BootTime()
        at System.Diagnostics.Process.BootTimeToDateTime(TimeSpan timespanAfterBoot)
        at System.Diagnostics.Process.get_StartTimeCore()
        at System.Diagnostics.Process.get_StartTime()

Screenshot_1649162406

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

This is the compiled apk files

Xamarin.Android 12 APK

NET 6.0 APK

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions