Macro Scheduler SDK GetVar problem...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
MarcinW
Junior Coder
Posts: 23
Joined: Thu Jul 23, 2020 11:24 pm

Macro Scheduler SDK GetVar problem...

Post by MarcinW » Wed Mar 10, 2021 4:01 pm

Hi,

I've noticed there's a problem with GetVar function when using MS SDK with C#. If string returned is larger than 29277 characters, next call to RunCode function will result in following error (at least for codes where variable assignment is done, e.g. Let>, Length>):

Code: Select all

System.Runtime.InteropServices.COMException: 'The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))'
and next call to GetVar function will result in following error:

Code: Select all

System.Runtime.InteropServices.COMException: 'Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))'
This happens even if CleanUp and Init is used after the problematic GetVar, so clearing variable table doesn't fix anything.

I tried to implement solution in my program, by splitting the string into smaller chunks based on 29277 char threshold, using MidStr before retrieving it through GetVar and it worked... sort of...
Now after getting the large string there's no issue with the RunCode function, at least haven't found one yet. However, GetVar throws this error when variable name is longer than 7 characters:

Code: Select all

System.Runtime.InteropServices.COMException: 'The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))'
With some exceptions, getting WIN_USEHANDLE or IGNOREERRORS works fine...

This variable name size error happens after I run GetVar on a string larger than 14533 character. Everything appears to work fine if I set my string splitting function threshold to 14533. However, I am not sure if I won't be getting any related errors in the future. Would be best if someone from MJT would fix the issue in the SDK itself.

MarcinW
Junior Coder
Posts: 23
Joined: Thu Jul 23, 2020 11:24 pm

Re: Macro Scheduler SDK GetVar problem...

Post by MarcinW » Wed Mar 10, 2021 4:10 pm

Below is the code I used to test, also used online random string generator to obtain strings.

Code: Select all

    public class ScriptRunnerTest
    {
        readonly MScript.MacroScript _axScript;

        public int MSGetVarCharLimit { get; set; }

        public ScriptRunnerTest()
        {
            MSGetVarCharLimit = 30000;
            //MSGetVarCharLimit = 29277;
            MSGetVarCharLimit = 14533;
            _axScript = new MScript.MacroScript();
        }

        public string TestRun(string text = "TEST")
        {
            _axScript.Init();
            
            _axScript.RunCode("Let>str_text=str_string", $"/str_string={text}");
            Console.WriteLine(_axScript.GetVar("LAST_ERROR"));
            string textFromMS = GetVar("str_text");

            _axScript.RunCode("Length>abcdefg,test_mee", null);
            _axScript.RunCode("MessageModal>test_mee", null);
            _axScript.RunCode("Let>IGNOREERRORS=%int_ignore_errors%", $"/int_ignore_errors=1");
            _axScript.RunCode("Let>WIN_USEHANDLE=%int_win_use_handle%", $"/int_win_use_handle=1");
            Console.WriteLine(_axScript.GetVar("IGNOREERRORS"));
            Console.WriteLine(_axScript.GetVar("WIN_USEHANDLE"));
            Console.WriteLine(_axScript.GetVar("LAST_ERROR"));
            Console.WriteLine(_axScript.GetVar("test_mee"));
            _axScript.Cleanup();


            return textFromMS;
        }

        public string GetVar(string varName)
        {
            string resultString = "";

            _axScript.RunCode($"Length>{varName},int_varLength", null);
            int varLength = Int32.Parse(_axScript.GetVar("int_varLength"));
            double getFloatIterations = (double)varLength / MSGetVarCharLimit;
            int getIterations = (int)Math.Floor(getFloatIterations);
            int remainder = varLength - (MSGetVarCharLimit * getIterations);

            for (int i = 0; i <= getIterations; i++)
            {
                int start = (MSGetVarCharLimit * i) + 1;
                int length = (i != getIterations) ? MSGetVarCharLimit : remainder;

                _axScript.RunCode($"MidStr>{varName},int_startPos,int_length,str_textPart", $"/int_startPos={start} /int_length={length}");
               resultString += _axScript.GetVar("str_textPart");
            }

            return resultString;
        }
    }

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Macro Scheduler SDK GetVar problem...

Post by Dorian (MJT support) » Wed Mar 10, 2021 4:25 pm

I will mention this to Marcus.
Yes, we have a Custom Scripting Service. Message me or go here

MarcinW
Junior Coder
Posts: 23
Joined: Thu Jul 23, 2020 11:24 pm

Re: Macro Scheduler SDK GetVar problem...

Post by MarcinW » Wed Mar 10, 2021 4:50 pm

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Macro Scheduler SDK GetVar problem...

Post by Marcus Tettmar » Wed Mar 10, 2021 8:47 pm

This is very odd. I can't see any reason at all for it to be limiting the returned string to 29277 characters. But we will investigate.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Macro Scheduler SDK GetVar problem...

Post by Marcus Tettmar » Thu Mar 11, 2021 1:51 pm

Just a preliminary update - I have been testing the OCX via VBScript with some very long text variables, both names and data, including variables set to the contents of files, with RunCodes and GetVars interspersed and have so far not had any errors. I am still not seeing any reason for the issue you are having. However, the next step will be to try in C#
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MarcinW
Junior Coder
Posts: 23
Joined: Thu Jul 23, 2020 11:24 pm

Re: Macro Scheduler SDK GetVar problem...

Post by MarcinW » Thu Mar 11, 2021 4:49 pm

Not sure about other languages but I tried it with c#. On my computer - next call to RunCode or GetVar fails if GetVar is called for a variable holding 29278+ characters.

That's the first issue, the next one is that next call to GetVar with a variable name longer than 7 chars throws an exception if there's more than 14533 characters.

I just had another dev check it on two separate computers, on both of them he gets an error on the GetVar itself if the string he's retrieving is longer than 14533 characters.

So it turns out that what triggers the errors and where they appear can vary from computer to computer, but GetVar is still the root of the problem and at least 14533 limit persists on all computers we checked it on.

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Macro Scheduler SDK GetVar problem...

Post by Marcus Tettmar » Thu Mar 11, 2021 6:54 pm

I haven't been able to test with C# yet (Visual Studio keeps crashing when I open it) but with VBScript I had variables with 50k+ characters in them and had no issues calling GetVar and RunCode several times with large variables like that. It's using the exact same OCX. So I'm not sure what the issue is here. Hopefully when I finally get Visual Studio running I can try it with C#.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Macro Scheduler SDK GetVar problem...

Post by Marcus Tettmar » Thu Mar 11, 2021 8:26 pm

Hi Marcin,

I have just sent you an updated version of the OCX which fixes this problem to your email.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MarcinW
Junior Coder
Posts: 23
Joined: Thu Jul 23, 2020 11:24 pm

Re: Macro Scheduler SDK GetVar problem...

Post by MarcinW » Thu Mar 11, 2021 11:35 pm

Hi Marcus,

Unfortunately I did not receive the email, I sent you a PM.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts