PowerShellExecutionService Error executing endpoint %Endpoint id%. Cannot index into a null array

I’m seeing this very strange / intermitten case where when i check a box i get this error about not being able to index into an array.

I’m not sure how to troubleshoot it, but it happens when i attempt to exececute

$CheckboxValue = ((Get-UDElement -Id $($CheckboxID) -ErrorAction Stop).Attributes[“checked”])

The PUD log (in debug mode) shows:
17:08:15 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executed action method UniversalDashboard.Controllers.ComponentController.SetElementSessionState (UniversalDashboard), returned result Microsoft.AspNetCore.Mvc.JsonResult in 0.3424ms.
17:08:15 [Info] Microsoft.AspNetCore.Mvc.Formatters.Json.Internal.JsonResultExecutor Executing JsonResult, writing value of type ‘<>f__AnonymousType2`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]’.
17:08:15 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executed action UniversalDashboard.Controllers.ComponentController.SetElementSessionState (UniversalDashboard) in 16.0438ms
17:08:15 [Info] Microsoft.AspNetCore.Hosting.Internal.WebHost Request finished in 30.6315ms 200 application/json; charset=utf-8
17:08:15 [Warn] PowerShellExecutionService Error executing endpoint 39e1a34c-2cf1-4f00-ab18-bc76b869b711. Cannot index into a null array.
at , : line 114
17:08:15 [Debug] PowerShellExecutionService ExecutionService constructor
17:08:15 [Debug] DashboardHub ClientEvent 39e1a34c-2cf1-4f00-ab18-bc76b869b711 onChange
17:08:15 [Debug] EndpointService Get() 39e1a34c-2cf1-4f00-ab18-bc76b869b711 87bcbba9-23fb-44c5-9ae6-7d09ea608ff6
17:08:15 [Debug] EndpointService Found session endpoint.

If it helps, the checkbox on change starts by creating an endpoint so i can pass some parameter data into it.

Essentially, my code looks like a more complex version of

https://docs.universaldashboard.io/components/checkbox the example at the bottom.

I create my checkbox similar, but I encapsulate the section starting after the “OnChange” in an endpoint and pass an object that I need to parse as an argument list.

I then before jumping out of the endpoint, I query the current checkbox state (so the example at the VERY bottom of the linked page), and then if the box is checked / not checked, i add / remove the object from a hash table.

Again, to reiterate the part that seems to be failing is the get-udendpoint. I’ve seen it fail in the checkbox, but also after the checkbox state has been updated / synced an I go back to query the state again.

I’m more than willing to upload my code, it’s way too much to try and block quote in here.

I’ve included a screen capture of the basic code (filtered out the logging commands i do)

Do you still get this from removing the error action stop? Just seems like it’s causing a terminating error due to that error action stop being enforced

I can take it out and try it, but wouldn’t I typically want that to happen? If it fails to get the udendpoint it seems like everything else in my script block would fail. I think the question is why is it erroring out.

cos your hitting a terminating error where you have a null array.

Right, but the question is why is it null. It was created in the code above. So it shouldn’t be null

In my firefox I downloaded the REACT extension tool which allows me to inspect the object…I have it sometimes where it doesn’t read the value from the component correctly…so maybe to eliminate reading it from the GET-UDELEMENT can you not set it as a SESSION variable…? Some of my dashboards even read input from a text file I outputted it too.
I mean can you simplify the page down to test the checkbox thing that you want to do?
Right now I’m super busy at work, but as always when asking for others to chip in I try to post as much of my code as possible to help others better understand the issue. Or create a simple dashboard page to show my issue. Think this would help in giving a definitive answer to why your page is not working as I do not fully know what your page is doing due to lack of code. Thanks

Oh i appreciate the help, sorry if that’s not coming across.

I honestly think this is a bug, not something in my code. I do a “new-udelement” followed by a “get-udelement”. My check box code is right off the web example in the docs. I don’t think trying to work around functionality makes sense.

Yes, I could ignore the whole udelement aspect of the checkbox and simply track state in my has table, but that seems to defeat the purpose of the endpoints.

For me, it becomes a matter of reliablity in the platform, and a feeling of trust in it. If i’m calling built in functionatliy and it does not work intermittenly, that’s a concern. I’m ok with bugs, as long as we acknowldege it’s a bug, and that we work to resolve it. What i’m not ok with, is saying when something doesn’t work, we should work around it.

I have no problem uploading my code, but there needs to be a facility for doing it more efficiently. I also suspect there is going to be a lot of confusion about what my variables are, where they came from, etc. This isn’t a simple “hello world” dashboard. This has custom functions, sub scripts, etc.

Going back to why i think it’s a bug. This issue happens very randomly. There are times where I load the dashboard up, and it happens in the first few check boxes. There are times where it’s fine after the dashbaord is loaded and doesn’t happen for sometimes 20 minutes. Then there are times where it never breaks. My code hasn’t changed.

@ericcsinger
based on my experience with UD this is not a bug, most of the time its the code, if you can post your code just for the check box and how you handle getting the value of that check box we can identify where the issue is.
when you check a check box that usually initiate an event and you should assign that event to a $session value as PSdevUK mentioned earlier. if the check box never been touched (checked) then its Null as expected.

It’s in the screenshot. Let me know if you think you need more than that.

If you could please use a trimmed down basic dashboard page of what you want to achieve. I understand sometimes this is difficult with sensitive data, server names etc, but just posting a basic example even if it doesn’t fully work will give people a lot more to work with to help you resolve the problem.

1 Like

Here you go. I linked an example to my github.

just wanted to bump this back up. I’m still seeing intermittent cases where checking the box results in a " can’t index into a null array"

Just a quick one on this before looking at the code, you mentioned you get ‘can’t index into a null array’ error, but theres no information on the error other than the exception message in this thread (just skimmed through, correct me if I’m wrong).
Can you use the console and inspect the $error variable to see if you can pull out a bit more detail from this, e.g where it came from, the line/char numbers, calling function, etc.
This may help narrow down the issue so we dont have to pick apart and replicate all the code end to end to test.
From experience and having this error in the past, it usually means one of your parameters is probably null / empty where it shouldn’t be and is not getting passed into a function as you expect it to be hence the function moaning that it cant index into a null array.

Hi,

Yes, there were line numbers. To make it a bit easier, I highlighted which lines threw the error in my screen shot so you could so the code.

One thing i’ve recently tried is changing ArgumentList[0] to simply ArgumentList. I’m going to see if that works any better.

Sorry, misunderstood.

Okay so of those two functions you have highlighted which are the same (get-udelement), the only parameter is the ID. So then we’re probably looking at two possibilities:

  1. Either the $checkboxID value is null at the time of error
  2. The $checkboxID that is being provided is not available to ‘get’ as an addressable element at that specific time.

I’d start by trying to obtain the value of that variable at the point of error. Stick that somewhere in your catch block and see what it’s actually populated with at the time.

P.S. Personally, I don’t think this is a bug, sometimes it’s easy to jump to this when problems arise. If it is, lets get to the point where we can evidence that, but right now, I think there’s more troubleshooting that needs to be done. Lets work out the root cause first before any assumptions are made. :slight_smile:

Just another comment on the code you posted to github, i was going to take it and run it on a quick demo page to see what you are actually trying to achieve as, while i’ve got an idea, I still dont fully understand what your code is doing. I removed the logging lines, changed the get-aduser line to pull just a couple of test users, but immediately it failed.

Noticed the following:

$Checkbox = New-UDCheckbox -Id $($CheckboxID) -ErrorAction Stop -OnChange (
This line ends with a (, shouldnt it be { for a scriptblock?

At the bottom of the page you’ve got:

New-UDParagraph -Content {
        $Graph_Data | Out-UDGridData
        }

Is this a typo? should it be New-UDGrid ?

Even after changing both these items and running the page, I get nothing back.

Lets just take a step back for a moment, what is it you’re trying to acheive/accomplish with this?
A list of AD users (samaccount names) as checkboxes, that when checked are added to an array you can use later/elsewhere?

Heres an example of both using session variables to populate an array with checked users in this way.
Or a cache variable, the cache example also shows how to retain the checkbox state when reloading the page.

If you wish to try either example, please paste this code into a page’s -endpoint scriptblock: