.netcomwshtypelibregasm

Windows Script Host cannot reference type library with version number in hexadecimal notation


I have .NET framework assembly which is exposed to COM. Recently, since the assembly minor version number reach 10, it stopped being usable from Windows Script Host (WSH).

[assembly: AssemblyVersion("1.10.0.0")]

The TypeLib registry entry for some obscure reason uses hexadecimal notation, when storing the version number:
BUG: The Regasm Tool Registers the Type Library with the Decimal Value Instead of the Hexadecimal Value

In this case it would be 1.a:

[HKEY_CLASSES_ROOT\TypeLib\{D766F0C8-9968-4A72-B918-D2780AEE7399}\1.a]
@="myassembly"

When the assembly is referenced in WSF file, WSH/cscript breaks whenever aā€“f "digits" are present in the version number. So it works for 1.0 or 1.9, does not work for 1.10 (1.a) or 1.15 (1.f), but works again for 1.16 (1.10) or 1.25 (1.19), and does not work again for 1.26 (1.1a) (I didn't check all intermediate values, but the pattern seems to be clear).

<job>
<reference object="myassembly.Class1" />
<script language="JScript">
...
</script>
</job>

The cscript says:

Windows Script Host: Cannot add reference : {D766F0C8-9968-4A72-B918-D2780AEE7399}

It seems like a bug in the WSH/cscript to me. Or am I missing something?


Solution

  • For the WSH reference node to work it must be capable of loading a COM Automation Type library (TLB) from the reference node.

    There are two ways for that:

    1. the COM server embeds a TYPELIB Win32 resource
    2. the CLSID registry key associated with the COM server indicates what is the TLB Id and its version

    It works w/o effort with COM servers such as ADODB.Recordset because they are in case 1).

    In the .NET case, the .NET .dll doesn't embed any TLB information so you must indicate it. So to fix it you must:

    Why you don't need that when minor version is < 10 is probably a bug in scrobj.dll (which implements WSH parsing). I suspect the code 1) uses default 1.something value when nothing is specified and 2) is broken when the major or minor versions are hexa. Here is a dump of the function that does it, it uses strtoul with a 10 radix/base instead of 16:

    enter image description here