How to determine if OS is 32 or 64 bit cross-platform on .NET Standard 1.5?

841 views Asked by At

I have been looking high and low for a solution to this, but although the question has been asked before the answers no longer apply to .NET Standard 1.5 and its cross-platform way of thinking. Also, this question is about the OS Architecture not the .NET platform architecture.

What I Tried

The best answer, Environment.Is64BitOperatingSystem is an API that is not implemented in .NET Standard 1.5.

The answer

/// <summary>Is64s the bit operating system.</summary>
/// <returns></returns>
if (IntPtr.Size == 8)
    // 64Bit
else
    // 32bit

is not what I need. Although still possible to do in .NET Standard, it determines the bitness of the .NET platform, not the underlying OS.

Nearly all of the other replies are using [DllImport("kernel32.dll")], which I am almost certain won't work on anything but Windows.

Question

So, how do I determine the bitness of the underlying OS for all of the platforms that .NET Standard 1.5 supports (Linux, iOS, Windows, Android, etc.)?

1

There are 1 answers

1
Knight King On BEST ANSWER

You can use System.Runtime.InteropServices.RuntimeInformation.OSArchitecture