Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example throws error saying Index was out of range. Must be non-negative and less than the size of the collection. #1

Open
Rathna-K opened this issue Nov 29, 2016 · 3 comments

Comments

@Rathna-K
Copy link

Rathna-K commented Nov 29, 2016

When you run the example it fails in the line below. it actually found the pancontroller (with mac address and everything) but showing 0 bulbs under it.

if (panController.Count == 0)
          {
              MessageBox.Show("Could not find any bulbs");
              mPowerGB.Enabled = false;
              mLabelsGB.Enabled = false;
              mLightStatusGB.Enabled = false;
              return;            
          }

          **mBulb = panController[0].Bulbs[0];**
        **mBulb = panController[0].Bulbs[0];**

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

@Bjorling
Copy link
Owner

Hi Rathna,

Wow, I did this a few years ago so pardon me for not being up to date here... I don't have any tools to check this now so I'm unable to do much myself but let me try assist you.

Are you getting the exception at this row:
if (panController.Count == 0)

Or at this row?:
mBulb = panController[0].Bulbs[0];

If it is at the second one I would advice you to check if there are any bulbs in the Bulb list as in below code:

if (panController.panController[0].Count == 0)
          {
              MessageBox.Show("Could not find any bulbs despite the pan-controller");
               mPowerGB.Enabled = false;
              mLabelsGB.Enabled = false;
              mLightStatusGB.Enabled = false;
              return;            
          }

Let us know the result!

Good luck,
Robin

@Rathna-K
Copy link
Author

Rathna-K commented Nov 29, 2016

Hi Robin,
Thank you for getting back to me so quickly and I appreciate you for that! :)
your snippet gives me this error:
Error 1 'System.Collections.Generic.List<LifxLib.LifxPanController>' does not contain a definition for 'panController' and no extension method 'panController' accepting a first argument of type 'System.Collections.Generic.List<LifxLib.LifxPanController>' could be found (are you missing a using directive or an assembly reference?)
But if your intention is to understand if there are any bulbs in the pancontroller the answer is no.

there are no bulbs in the pancontroller but there are two pancontrollers with macid in them. here is couple of screens from visual studio: http://imgur.com/a/rVlO0

Thanks,
Rathna

@Rathna-K
Copy link
Author

Hello Robin, any luck with this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants