more G-Labs products

Author Topic: Error: Line 0, Column 0 (Object reference...)  (Read 1719 times)

September 18, 2014, 11:00:33 AM
Read 1719 times

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
This is a problem that's been bothering me for a while now, I can't seem to fix it... :(

I have a number of scripts that are initiated by a Z-wave wall switch. Depending on the time of day the hue lights get a different colour, so I've created C# scripts for them.

The scripts work fine after saving them (action -> update), they get an orange/yellow ball icon and run well.

The problem arises after a reboot of the server (I'm running a BananaPi now, but the problem was also there on a RasPi). After the reboot all of the scripts are disabled with a dark red ball icon. When I enable them again, they get a red ball icon, but the script runs OK.

When I open the script I get the following message:
Line 0, Column 0 (Trigger Code):
  Object reference not set to an instance of an object.


I think the problem lies with my Wall switch Trigger line, because all other scripts work (time based, weather based), only the wall switch scripts give me this problem.

Here is one of the the return codes I'm using the others vary only in Switch name and value:
Code: [Select]
return (Modules.WithName("Switch 1").Get().Parameter("Sensor.Generic").DecimalValue == 22);
After saving the script again with action -> update, the error goes away until the next reboot.

The script settings are:
- Program Type: C#
- Trigger Type: when condition evaluation switches to 'true'

I'm running version 1.00 beta r411

I've attached two images, one is the error message, the other is what the Automation windows looks like after a reboot.

Any help would be greatly appreciated.

September 18, 2014, 11:14:57 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Perhaps the module "Switch 1" is not yet available at startup as z-wave node discovery start after all automation programs are started.
So the code should first check that the module exists before trying reading module parameters (Sensor.Generic).

Code: [Select]

var wallSwitch = Modules.WithName("Switch 1").Get();

return (wallSwitch.WasFound && wallSwitch.Parameter("Sensor.Generic").DecimalValue == 22);



g.
« Last Edit: September 18, 2014, 12:50:24 PM by Gene »

September 18, 2014, 12:13:40 PM
Reply #2

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Thank you very much Gene, that did the trick!  :)

Edit: In case anyone copies the code above, you'll need to change the name of variable 'switch' to something else like 'wallSwitch'. (switch is a reserved word in C#)
« Last Edit: September 18, 2014, 12:36:38 PM by mvdarend »

September 18, 2014, 12:50:58 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer