An error The name '<XCastedExpressionImpl>.toColor()

I have a simple rule controlling the Mysensors dimmer. It was working fine in OH1 but after moving to OH2 throws an exception

2016-06-08 22:48:06.739 [INFO ] [marthome.event.ItemStateChangedEvent] - s_RGB_light changed from 140.0,100.0,100 to 0.0,0.0,0.0
2016-06-08 22:48:06.743 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'Set s_RGB_light value': An error occured during the script execution: The name '<XCastedExpressionImpl>.toColor()' cannot be resolved to an item or type.

Wonder what did i miss

rule "Set s_RGB_light value"
when
Item s_RGB_light changed
then
val Color color = (s_RGB_light.state as HSBType).toColor()
val String rgb = String::format("%1$02x%2$02x%3$02x", color.red, color.green, color.blue)
publish("mqt", "mygateway1-in/36/0/1/0/40", rgb)
end

Should i install exec mapping or someother? Might be the cause?

Ok. Installed all the transormations
transformation = exec,javascript,jsonpath,map,regex,scale,xpath,xslt
Moved the rule to its own file rgb.rule. SO the only code in the file is (no comments nothing)

rule "Set s_RGB_light value"
when
    Item s_RGB_light changed
then
    val Color color = (s_RGB_light.state as HSBType).toColor()
    val String rgb = String::format("%1$02x%2$02x%3$02x", color.red, color.green, color.blue)
    publish("mqt", "mygateway1-in/36/0/1/0/40", rgb)

Still the same

2016-06-09 20:40:28.721 [INFO ] [marthome.event.ItemStateChangedEvent] - s_RGB_light changed from 315,36,100 to 319,52,100
2016-06-09 20:40:28.723 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'Set s_RGB_light value': An error occured during the script execution: The name '<XCastedExpressionImpl>.toColor()' cannot be resolved to an item or type.

In openhab in the beginning of the file i had

import org.openhab.core.library.types.HSBType
import java.awt.Color

But seems this libraries are absent in OH2

This is because the ESH core should not depend on awt (as it is supposed to be headless). See http://docs.openhab.org/tutorials/migration#rules for a workaround.