1

In my VB.NET app using .NET Framework 4.5 I have this line of code:

ThisOS.Text = My.Computer.Info.OSFullName

It has been working as expected without problems. Suddenly yesterday a client using 9 x Windows 10 machines reports an unhandled exception on 2 of them which caused the entire app the crash. After much error trapping, recompiling, uploading and installing I eventually pinpointed that line of code as the source of the exception. I changed the code as below and the problem was solved.

' this causes an exception on some computers
Try
    ThisOS.Text = My.Computer.Info.OSFullName
Catch ex As Exception
      ThisOS.Text = "Unknown OS"
End Try

Does anybody know why this happens? I'd like to be able to fix the root cause instead of just catching the error. Exception detail:

System.Exception: Exception of type 'System.Exception' was thrown.
   at SheriffSQL6.FrmAsheriff.FrmAsheriff_Load(Object sender, EventArgs e) in C:\vbcode.net\SheriffSQL6\SheriffSQL6\FrmAsheriff.vb:line 155
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I suggested to reset Windows.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Ray E
  • 134
  • 1
  • 9

1 Answers1

3

Fortunately it is a documented bug, install WMI to fix it:

https://learn.microsoft.com/en-us/dotnet/visual-basic/misc/could-not-obtain-full-operation-system-name-due-to-internal-error

A call to the My.Computer.Info.OSFullName property failed. A possible cause for this failure is if Windows Management Instrumentation (WMI) is not installed on the current computer.

To correct this error Add a Try...Catch block around the call to the My.Computer.Info.OSFullName property.

For more information about WMI and how to install it, go to and search for "Windows Management Instrumentation Core".

OP mentioned:

After much error trapping, recompiling, uploading and installing I eventually pinpointed that line of code as the source of the exception

Tip to track down these random errors easily, take a look at my "UserActionLog" https://stackoverflow.com/a/30525957/495455

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • That's interesting because the documentation for the property itself says that it should just return the same value as `OSPlatform` if WMI is not installed. – John Sep 15 '22 at 05:34
  • 2
    As someone who worked previously in Microsoft PSS/CSS (Pro Dev Support) the KBs are more official than the MSDN docs. – Jeremy Thompson Sep 15 '22 at 05:35
  • @Jeremy. Thank you for that. Now I know. Hope others see this and don't get caught out like I did. – Ray E Sep 15 '22 at 06:32
  • @RayE you're welcome mate, your profile gave me a giggle. Happy coding! – Jeremy Thompson Sep 15 '22 at 06:33