Clearscript: Need a way to import enums from type libraries and on-the-fly interop assemblies

Created on 28 Nov 2019  路  3Comments  路  Source: microsoft/ClearScript

Hi!

I am trying to open a text file using v8 script engine. I add the com type FSO like this:

AddCOMType("FSO", "Scripting.FileSystemObject");

and so I can read a text file easily like this:

f = new FSO();
var stream = f.OpenTextFile("d:/tesffile.txt", );
content = stream.ReadAll());

That works! Problems start when I want to pass more parameters to the OpenTextFile method (e.g. if I want to read the text file as non ASCII text). I always get comiler errors like "Invalid argument specified for parameter 'IOMode'" etc, no matter what kind of parameters I specify. I suspect we have problems with the default parameters?

I can work around this adding my custom methods, but I was wondering if there's something I missed using the Scripting.FileSystemObject via ClearScipt (works with ActiveX stuff using VBScript....)?

Thank you for your input!

bug fixed

All 3 comments

Hi @flat-eric147,

Thanks for reporting this issue. Unfortunately there's no solution at the moment. Because we consider FileSystemObject support essential, we'll treat it as a bug.

For now, if you must use FileSystemObject, try importing it on the .NET side by adding a project reference to the "Microsoft Scripting Runtime" type library. Make sure "Embed Interop Types" is set to "False" for the reference. You should then be able to expose both FileSystemObjectClass and IOMode to script code as if they were normal managed types.

Thanks again!

Thanks a lot, great workaround!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drearyrainDeng picture drearyrainDeng  路  3Comments

AllNamesRTaken picture AllNamesRTaken  路  7Comments

arthurshayne picture arthurshayne  路  3Comments

egooner picture egooner  路  3Comments

andrejpk picture andrejpk  路  7Comments