saucepleez / taskt

taskt (pronounced 'tasked' and formely sharpRPA) is free and open-source robotic process automation (rpa) built in C# powered by the .NET Framework
http://www.taskt.net/
1.09k stars 350 forks source link

ExecuteScript and ExecuteCommand produce errors when assigning multiple variables on startup #237

Open steinjo opened 3 years ago

steinjo commented 3 years ago

Hi, first of all: thank you for providing this great piece of software to us!

Here is my issue (it might be two different ones):

I have a script (called masterTask.xml) that has one line (RunTask) to execute another script (called slaveTask.xml). During callup, master Task is assigning values to the variables in slaveTask.

masterTask.xml: masterTask.txt

slaveTaks.xml: slaveTask.txt

This works perfectly well when executing masterTask.xml within taskt. However, when I pass the same script as stored in file masterTask.xml via postman in header-variable ScriptData to the listener-API ExecuteCommand of taskt (after having eliminated spaces, tabs and linebreaks with this tool https://tools.knowledgewalls.com/online-multiline-to-single-line-converter I get this error log:

2020-09-30 08:00:36.732 +02:00 [INF] Engine Class has been initialized 2020-09-30 08:00:36.735 +02:00 [INF] Client requesting to execute script independently 2020-09-30 08:00:36.736 +02:00 [INF] Bot Engine Started: 30.09.2020 08:00:36 2020-09-30 08:00:36.754 +02:00 [INF] Deserializing XML 2020-09-30 08:00:36.781 +02:00 [INF] Result Code: Error 2020-09-30 08:00:36.781 +02:00 [INF] Error: System.InvalidOperationException: Fehler im XML-Dokument (1,1934). ---> System.Xml.XmlException: Unerwartetes Ende der Datei bei der Syntaxanalyse von Name. Zeile 1, Position 1934. bei System.Xml.XmlTextReaderImpl.Throw(Exception e) bei System.Xml.XmlTextReaderImpl.Throw(String res, String arg) bei System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg) bei System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) bei System.Xml.XmlTextReaderImpl.ParseElement() bei System.Xml.XmlTextReaderImpl.ParseElementContent() bei System.Xml.XmlTextReaderImpl.Read() bei System.Xml.XmlTextReader.Read() bei System.Data.DataTextReader.Read() bei System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested) bei System.Data.XmlDataLoader.LoadData(XmlReader reader) bei System.Data.DataTable.ReadXmlDiffgram(XmlReader reader) bei System.Data.DataTable.ReadXml(XmlReader reader, XmlReadMode mode, Boolean denyResolving) bei System.Data.DataTable.ReadXmlSerializable(XmlReader reader) bei System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader reader) bei System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable, Boolean wrappedAny) bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read113_RunTaskCommand(Boolean isNullable, Boolean checkType) bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read180_ScriptCommand(Boolean isNullable, Boolean checkType) bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read181_ScriptAction(Boolean isNullable, Boolean checkType) bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read183_Script(Boolean isNullable, Boolean checkType) bei Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read184_Script() --- Ende der internen Ausnahmestapelüberwachung --- bei System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) bei System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) bei taskt.Core.Script.Script.DeserializeXML(String scriptXML) bei taskt.Core.Automation.Engine.AutomationEngineInstance.ExecuteScript(String data, Boolean dataIsFile) Troubleshooting:

Then I tried to use ExecuteCommand (which is an alternative approach to solve my business case) by copying the following JSON-code of the masterTask to postman {"$type":"taskt.Core.Automation.Commands.RunTaskCommand, taskt","v_taskPath":"C:\\Users\\xxx\\Documents\\taskt\\My Scripts\\tests\\slaveTask.xml","v_VariableAssignments":[{"VariableName":"v_loginName","VariableValue":"testnameNeu","VariableReturn":"Yes"},{"VariableName":"v_loginPassword","VariableValue":"testpwNeu","VariableReturn":"Yes"}],"v_AssignVariables":true,"CommandID":"42d7bd45-e714-4d81-8794-57f7c0208ef6","CommandName":"RunTaskCommand","IsCommented":false,"SelectionName":"Run Task","DefaultPause":0,"LineNumber":1,"PauseBeforeExeucution":false,"DisplayForeColor":"SteelBlue","v_Comment":null,"CommandEnabled":true,"CustomRendering":true}

This produces the following error in postman (no log-entry in taskt, the script did not execute): An error occured: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. bei taskt.Core.Automation.Engine.AutomationEngineInstance.ExecuteCommand(ScriptAction command) bei taskt.Core.Server.LocalTCPListener.ProcessRequest(String data, String[] messageContent, NetworkStream stream) image

Thanks in advance for your support. I'd be more than happy to translate the German error message for you if it helps.

naga1992 commented 3 years ago

It would be great if you can translate the error to english so that i can take a look

steinjo commented 3 years ago

Hi, thanks for adressing this and no problem with the translation.

Here is the first error-log from above post: 2020-09-30 08:00:36.732 +02:00 [INF] Engine Class has been initialized 2020-09-30 08:00:36.735 +02:00 [INF] Client requesting to execute script independently 2020-09-30 08:00:36.736 +02:00 [INF] Bot Engine Started: 30.09.2020 08:00:36 2020-09-30 08:00:36.754 +02:00 [INF] Deserializing XML 2020-09-30 08:00:36.781 +02:00 [INF] Result Code: Error 2020-09-30 08:00:36.781 +02:00 [INF] Error: System.InvalidOperationException: Error in XML-Dokument (1,1934). ---> System.Xml.XmlException: Unexpected End of file while analyzing syntax of Name. Line 1, Position 1934. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg) at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) at System.Xml.XmlTextReaderImpl.ParseElement() at System.Xml.XmlTextReaderImpl.ParseElementContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read() at System.Data.DataTextReader.Read() at System.Data.XmlDataLoader.LoadTable(DataTable table, Boolean isNested) at System.Data.XmlDataLoader.LoadData(XmlReader reader) at System.Data.DataTable.ReadXmlDiffgram(XmlReader reader) at System.Data.DataTable.ReadXml(XmlReader reader, XmlReadMode mode, Boolean denyResolving) bei System.Data.DataTable.ReadXmlSerializable(XmlReader reader) at System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader reader) at System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable, Boolean wrappedAny) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read113_RunTaskCommand(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read180_ScriptCommand(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read181_ScriptAction(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read183_Script(Boolean isNullable, Boolean checkType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderScript.Read184_Script() --- End of internal exception batch supervision --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) at taskt.Core.Script.Script.DeserializeXML(String scriptXML) at taskt.Core.Automation.Engine.AutomationEngineInstance.ExecuteScript(String data, Boolean dataIsFile)

And this is the second error log from Postman An error occured: System.NullReferenceException: Reference to object was not tied to one object instance. at taskt.Core.Automation.Engine.AutomationEngineInstance.ExecuteCommand(ScriptAction command) at taskt.Core.Server.LocalTCPListener.ProcessRequest(String data, String[] messageContent, NetworkStream stream)

Let me know, if you need more information or testing.

Thanks, Jorg

naga1992 commented 3 years ago

Hi Jorg

can you change the paramter CommandData to ScriptData and try executing the script from postman once again , from the code i can see that taskt expectes ScriptData not CommandData , i guess that might be the issue , please try and do let me know

steinjo commented 3 years ago

Hi naga, thanks for getting back on this. I admit, I don't understand what you are asking for.

The postman screenshot you see above is from the second scenario, I described when I used ExecuteCommand as a workaround. I even tried to follow your advise an ran ExecuteCommand with ScriptData, but that doesn't lead anyhere (log entry in taskt "Client Command Data Not Found"), which seems quite obvious to me, so I belive we have a misunderstanding.

Again, my problem description: The issue according to the above first error log comes up when using ExecuteScript (with ScripData = <?xml version="1.0" encoding="...) with two variables. ExecuteScript runs smoothely when trying to set only one variable. My preferred solution is using ExecuteScript with even more than one variable. If that is not possible, I could work with ExecuteCommand, but that also produces the error (a different one), described above.

Thanks for your help and let me know if I am on the wrong path :-)

Jorg