exceptionless / Exceptionless.Net

Exceptionless clients for the .NET platform
https://exceptionless.com
Other
554 stars 142 forks source link

Show correct version for Windows 10 on the Environment tab #239

Closed PCAssistSoftware closed 1 year ago

PCAssistSoftware commented 3 years ago

Environment tab needs to show Windows 10 build version as currently just shows:

image

Which is not technically correct anyway as that value (6.2.x) refers to Windows 8 and Server 2012 NOT Windows 10

Would be handy to see what you see in Winver e.g. Version 20H2 (OS Build 19042.630)

As that is much more informative and often crashes/errors are related to specific builds of Windows 10

Not sure how you pull existing OS Version info? But correct values can be found via Powershell, command line (systeminfo) or registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)

In my opinion this is quite important to know when comparing errors from different machines, as in the past I have found error is not actually my product it is just because a machine has updated to latest Windows 10 build which has then broken something!

PCAssistSoftware commented 3 years ago

As per email from Blake this can be fixed client end by updating you Application Manifest File - just tested it and works perfectly

https://www.prugg.at/2019/09/09/properly-detect-windows-version-in-c-net-even-windows-10/

ejsmith commented 3 years ago

@wingers999 I really don't want to have to use the registry to get this information. Is there no way to get this information directly from a managed API?

PCAssistSoftware commented 3 years ago

RuntimeInformation.OSDescription gives the correct information, or at least the same information as changing the app.manifest does e.g. 10.0.19042.0 - if you want informaiton such as 1903, 2009, 20H2 etc then reading it from registry seems to be only way

ejsmith commented 3 years ago

https://docs.microsoft.com/en-us/dotnet/api/system.environment.osversion?view=net-5.0

That says that starting in .NET 5.0 it will always return the correct Windows version.

Also, I see some code on GitHub getting OS like this:

private static string GetOSVersion()
{
  ManagementObjectSearcher wmiOperatingSystemSearcher = new ManagementObjectSearcher("SELECT Version FROM Win32_OperatingSystem");
  ManagementObjectCollection wmiOperatingSystemCollection = wmiOperatingSystemSearcher.Get();

  foreach (ManagementObject wmiOperatingSystemObject in wmiOperatingSystemCollection)
  {
    try
    {
      var version = wmiOperatingSystemObject["Version"].ToString();
      return version;
    }
    catch (ManagementException ex) { }
  }
  return Environment.OSVersion.Version.ToString(3);
}

The problem with either the registry or that WMI code is that it does not work cross platform.

PCAssistSoftware commented 3 years ago

That is interesting to know, at least when I move to .NET 5 it will be okay. For now I am quite happy modifying the app.manifest to get my apps reporting the correct value if needed.

Yes that WMI method seems to work okay but I take your point re cross platform

niemyjski commented 3 years ago

I think the best approach would be to use : https://stackoverflow.com/questions/2819934/detect-windows-version-in-net

Alternative solution

If you don't like adding app.manifest to your project, you can use OSDescription which is available since .NET Framework 4.7.1 and .NET Core 1.0.

string description = RuntimeInformation.OSDescription;
PCAssistSoftware commented 3 years ago

Yes as above quite happy to add manifest or if not I will use RuntimeInformation.OSDescription as suggested in previous post in a plugin to send correct information - thanks

niemyjski commented 1 year ago

I'm closing this as we can't really do much on full framework for this until we move to .NET Framework 4.7.1 which we have to wait for 4.6.2 to be deprecated (a few years).

Reviewing the code, we are doing the correct thing today on .NET Core.