title: BluetoothLEDevice.FromIdAsync Returns Uncastable __ComObject
body: <p><em>Before we even start: In researching this problem I've looked at dozens of posts here and elsewhere, and realize that VB is the <strong>worst</strong> for Bluetooth programming. However, this is for a client who has a massive legacy VB system and I have no choice.</em></p>
  <p>According to MS documentation, the <code>BluetoothLEDevice.FromIdAsync</code> is supposed to return a BluetoothLEDevice object but on my system it returns a generic <code>System.__ComObject</code> that I can't cast to a BluetoothLEDevice. I have tried Cast and DirectCast but neither work. The sample C++ code I've looked at doesn't require any type of casting; the variable is declared and set using the <code>BluetoothLEDevice.FromIdAsync</code> function without any dramas.</p>
  <p>Here is my test code.</p>
  <pre><code>Private Sub ConnectToDevice(di As DeviceInformation)
      '
      ' di.id = &quot;BluetoothLE#BluetoothLE48:5f:99:3c:fd:36-84:2e:14:26:9e:7b&quot;
      '
      Debug.Print(&quot;Connecting To &quot; &amp; di.Name &amp; &quot; at &quot; &amp; Now.ToShortTimeString)
      Dim genericObject As Object
      Dim myDevice As BluetoothLEDevice
      Try
          genericObject = BluetoothLEDevice.FromIdAsync(di.Id)
      Catch ex As Exception
          Debug.Print(ex.Message)
      End Try
      If Not IsNothing(genericObject) Then Debug.Print(&quot;Using 'Object' yeilds &quot; &amp; genericObject.ToString)
      Try
          myDevice = BluetoothLEDevice.FromIdAsync(di.Id)
      Catch ex As Exception
          Debug.Print(ex.Message)
      End Try
  End Sub
  </code></pre>
  <p>And here is the output:</p>
  <pre><code>Connecting To TM-2021090161 at 2:08 PM
  Using 'Object' yeilds System.__ComObject
  Exception thrown: 'System.InvalidCastException' in testBTLE.exe
  Unable to cast object of type 'System.__ComObject' to type 'Windows.Devices.Bluetooth.BluetoothLEDevice'.
  </code></pre>
  <p>And a screen shot of the returned genericObject:
  <a href="https://i.stack.imgur.com/D3NyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D3NyD.png" alt="Watch Window - Generic ComObject" /></a></p>