Using ATVO.ThemesSDK.Data.Results and System.Windows.Media in the same script

Posts: 72
So I have a few scripts I'm working on for fastest lap, push to pass, and CSV/class color overrides. All of these require IEntitySessionResult to find fastest lap, if they're using push to pass, if they exist in the CSV, etc. The theme editor shows zero errors when editing but when the theme is loaded, the event log continuously spits out the following error:

Error executing script: Unable to cast object of type 'System.Windows.Media.Color' to type 'ATVO.ThemesSDK.Data.Results.IEntitySessionResult'.

Last time I tested them, the fastest lap and P2P scripts worked, but that was a few updates ago and I did not check the event log when testing.
Posts: 72
After more testing, this seems to also happen on my CSV name override script as well:

Error executing script: Unable to cast object of type 'System.String' to type 'ATVO.ThemesSDK.Data.Results.IEntitySessionResult'.

Again, nothing wrong in the theme editor, just shows this when trying to run the script in a loaded theme.
Posts: 72
Don't want to spam a thread but i did complete more testing and the errors are gone with a re-formatted script - don't know how or why. Now the issue is getting class information with result information, getting the same "unable to cast" error in the event log when I try and pull both sets of data into one script.
Posts: 785
Most likely there is sometimes coming data with unexpected type in the 'value' of the script function, and you try to cast it to IEntitySessionResult while it's actually a Color or string. You should just check the type is correct and if not do nothing. You can do it via the "as" casting like this:
var result = value as IEntitySessionResult;
if (result == null)
{
// it was not type IEntitySessionResult
}