-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing array from JScript to COM object: Error converting argument 1 to type class StringArray #631
Comments
Hi @FrankLeinbach, First, a general comment: Because ClearScript's primary goal is to provide full access to .NET from script code, its default behavior is to marshal most .NET objects, including arrays, by proxy. So, instead of an array type that's native to the script language, script code gets a special object – a proxy – that acts as a reference to the managed array and provides full access to it. The script engine has no way of determining that the proxy refers to an array and no way of converting it to another array type.
It's difficult to answer without knowing what Thanks! |
Thank you for the quick response. I will try this on Monday when I'm back at my computer and post whether or not it worked. |
This appears to work. Thank you for the help. Are there any issues that are brought up by MarshalArraysByValue? |
Hi @FrankLeinbach,
That's great to hear. Thank you!
Yes, there are caveats:
Good luck! |
Discussed in #630
Originally posted by FrankLeinbach January 24, 2025
I have run into a breaking issue in moving from an implementation I made of IActiveScript to ClearScript.
I have JScript that creates a COM object like this:
var thirdPartyObj = new ActiveXObject("ThirdPartyObj.API");
within the script, I also create an array of strings to pass to a method on this object:
In the previous iteration, I had a problem directly calling the third party object's method with this array, like this:
thirdPartyObj.ProcessStrings(stringData)
This gave me an error. To circumvent this, I created a global host object function that simply took the JavaScript array and returned an array of String (string[]).
thirdPartyObj.ProcessStrings(JSArrayToStringArray(stringData))
;This worked in the original IActiveScript implementation.
Now, with ClearScript, every time I pass this to the ProcessStrings function, regardless of passing it directly or wrapping the array in the function, I get the error "Error converting argument 1 to type class StringArray".
I have tried a number of engine properties, but none have worked:
Any insight would be appreciated.
The text was updated successfully, but these errors were encountered: