Object Reference Not Set...

Apr 24, 2012 at 4:17 PM


First of all, great wrapper!!

I have one issue....when running deployed application, I get Object Ref Not Set errors when referencing the PowerStatus objects.  Device is discovered fine and other objects like DeviceID, Platform, ConnectionType work fine.  Also, EVERYTHING works fine while debugging in VS2008.  I have deployed the RAPI2.dll to my target environment.  I have also tried both 1.3.1 and 2.0 and both exhibit the same issue.


I suppose there must be a dependency I'm missing???

Any help would be greatly appreciated.



Apr 24, 2012 at 8:56 PM

Check to make sure RemoteDevice.Status == DeviceStatus.Connected before trying to access the PowerStatus property. The test app, RAPIDeviceUI, has code within it that accesses the PowerStatus and reports it. Try downloading that from the 2.0 download page and see if you get the same error. If not, check out the code and see what is different from your use.

Apr 24, 2012 at 9:21 PM

Thanks for the follow up.  Below is a snippet of failing code.  I narrowed it down to the ConnectionType being offending code.  After ConnectionType is referenced, any other property fails with an object not set.  Very strange that this only occurs in the compiled version of my app.  In the example below, ConnectionType returns fine, but exception is thrown on the Status property.  Everything is fine if I reference the ConnectionType last.  I just got rid of it any way since it was left over from experimenting with wrapper...not very necessary!!



   Private Sub ScanForDevice_Bad()
      'RAPI Scan For Device
      rapiDev = rapiMgr.Devices.FirstConnectedDevice
      If Not rapiDev Is Nothing Then
         If rapiDev.Status = System.Devices.DeviceStatus.Connected Then
            lblConnection.Text = rapiDev.ConnectionType.ToString     'OFFENDING STATEMENT
            lblStatus.Text = rapiDev.Status
         End If
      End If
   End Sub

Apr 24, 2012 at 9:22 PM

Sorry...behavior same on v1.3 and v2.0


Apr 25, 2012 at 6:53 AM

Status returns an enumerated type so you need to call the ToString method on it to expose it as a string.

Apr 25, 2012 at 1:43 PM

Yes, I originally had it displaying the enumerated string.  I just stripped things away to narrow down issue, which I concluded was caused by reading the ConnectionType property.  So rapiDev.Status is valid in the proceeding IF statement, but rapiDev.Status is hosed after reading the ConnectionType property.  Again, this only does this in my compiled application....everything is fine in IDE.

Apr 26, 2012 at 6:28 PM

After hours of debugging and searching the web, I found the problem and have corrected it in the latest download. It had to do with the differences in how x86 and x64 handle interop structure boundaries and passing an int instead of a uint for the IPAddress field. Crazy.

Apr 27, 2012 at 2:28 PM

Hey, that's great...thanks for tracking that down.  Sorry it got you bogged down....sounds like a strange problem.