.NET Forum / Languages / JScript / October 2005
ActiveXObject("htmlfile") and Jscript.NET
|
|
Thread rating:  |
Eugene Gershnik - 09 Oct 2005 18:32 GMT Consider the following code
var doc = new ActiveXObject("htmlfile"); doc.write("abc");
When executed under WSH this code runs without problems. However, compiling as
jsc.exe /fast-
and running it produces
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80020005): T ype mismatch.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at mshtml.HTMLDocumentClass.write(Object[] psarray) at invoker0.Invoke(Object , Object[] ) at Microsoft.JScript.JSMethodInfo.Invoke(Object obj, BindingFlags options, Bi nder binder, Object[] parameters, CultureInfo culture) at Microsoft.JScript.LateBinding.CallOneOfTheMembers(MemberInfo[] members, Ob ject[] arguments, Boolean construct, Object thisob, Binder binder, CultureInfo c ulture, String[] namedParameters, VsaEngine engine) at Microsoft.JScript.LateBinding.Call(Binder binder, Object[] arguments, Para meterModifier[] modifiers, CultureInfo culture, String[] namedParameters, Boolea n construct, Boolean brackets, VsaEngine engine) at Microsoft.JScript.LateBinding.Call(Object[] arguments, Boolean construct, Boolean brackets, VsaEngine engine) at JScript 0.Global Code() at JScript Main.Main(String[] )
Any idea of what is wrong here and how to fix it?
 Signature Eugene
Serge Baltic - 12 Oct 2005 12:17 GMT Hello,
EG> Consider the following code EG> EG> var doc = new ActiveXObject("htmlfile"); EG> doc.write("abc"); EG> When executed under WSH this code runs without problems. However, EG> compiling as EG> EG> jsc.exe /fast-
What's the IDL prototype of doc.write?
(H) Serg
Eugene Gershnik - 12 Oct 2005 19:15 GMT > Hello, > [quoted text clipped - 8 lines] > > What's the IDL prototype of doc.write? "htmlfile" is an MS component. Friendly name: HTML Document CLSID: {25336920-03F9-11CF-8FD0-00AA00686F13} InProcServer32: %SystemRoot%\System32\mshtml.dll
Opening its type library in OleView gives this prototype for write under dispinterface IHTMLDocument2
[id(0x0000041e), vararg] void write([in] SAFEARRAY(VARIANT) psarray);
This method is also documented in http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/refer ence/ifaces/document2/write.asp
Additionally there is some interesting stuff in this component registry entry under InProcServer32. This is something that that I haven't seen before
Assembly REG_SZ Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Class REG_SZ mshtml.HTMLDocumentClass RuntimeVersion REG_SZ v1.0.3705 ThreadingModel REG_SZ Apartment
It looks like .NET installed some replacement assembly that wraps this component and doesn't quite work right.
-- Eugene
Serge Baltic - 13 Oct 2005 10:48 GMT Hello,
>> Hello, >> What's the IDL prototype of doc.write? EG> void write([in] SAFEARRAY(VARIANT) psarray);
So why not pass an array of objects, if it accepts an array?
(H) Serge
Serge Baltic - 13 Oct 2005 10:53 GMT Hello,
EG> Additionally there is some interesting stuff in this component EG> registry entry under InProcServer32. This is something that that I EG> haven't seen before EG> EG> Assembly REG_SZ Microsoft.mshtml, Version=7.0.3300.0, EG> Culture=neutral, EG> PublicKeyToken=b03f5f7f11d50a3a EG> Class REG_SZ mshtml.HTMLDocumentClass EG> RuntimeVersion REG_SZ v1.0.3705 EG> ThreadingModel REG_SZ Apartment EG> It looks like .NET installed some replacement assembly that wraps EG> this component and doesn't quite work right.
Maybe you just don't quite call it right? ;-)
Looking at the write function prototype in the interop assembly I can see that:
.method public hidebysig newslot virtual instance void write([in] object[] marshal() psarray) runtime managed internalcall { .custom instance void [mscorlib]System.Runtime.InteropServices.PreserveSigAttribute::.ctor() .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( int32(0x0000041E) ) .override mshtml.DispHTMLDocument::write }
So, it's doc.write(["abc"]) in JScript, I guess; at least, it's definitely doc.write(new Object[]{"abc"}) in C#.
(H) Serge
Eugene Gershnik - 13 Oct 2005 17:34 GMT >> void write([in] SAFEARRAY(VARIANT) psarray);
>So why not pass an array of objects, if it accepts an array? You missed [vararg] in the function declaration. This is simply an IDL way of saying that it has variable number of arguments. JScript supports these natively.
> Maybe you just don't quite call it right? ;-) Wel it was write("abc") since the beginning of time ;-) This method is one of the most frequently used in ASP programming; just google for document.write
In any case I tried your suggestion
var doc = new ActiveXObject("htmlfile"); doc.write(["abc"]);
and got exactly the same error as before.
 Signature Eugene http://www.gershnik.com
Serge Baltic - 17 Oct 2005 17:20 GMT Hello,
EG> You missed [vararg] in the function declaration.
Uh, sorry, did not notice it as it was on another line.
EG> In any case I tried your suggestion EG> EG> var doc = new ActiveXObject("htmlfile"); EG> doc.write(["abc"]); EG> and got exactly the same error as before.
And what if you pass a strongly-typed argument?
(H) Serg
Eugene Gershnik - 18 Oct 2005 06:52 GMT >> In any case I tried your suggestion >> [quoted text clipped - 3 lines] > > And what if you pass a strongly-typed argument? I tried:
1)
import System;
var doc = new ActiveXObject("htmlfile"); var x : System.String = "abc" doc.write(x);
2)
import System;
var doc = new ActiveXObject("htmlfile"); var x : System.String = "abc" doc.write([x]);
3)
import System;
var doc = new ActiveXObject("htmlfile"); var x : System.String[] = new System.String[1]; x[0] = "abc" doc.write(x);
4)
import System;
var doc = new ActiveXObject("htmlfile"); var x : System.String[] = new System.String[1]; x[0] = "abc" var y : System.Object[] = x; doc.write(y);
All with the same result.
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80020005): T ype mismatch.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at mshtml.HTMLDocumentClass.write(Object[] psarray) ....
Assuming mshtml.HTMLDocumentClass is not broken it appears that JScript.NET is :-(
-- Eugene
Bruce Barker - 19 Oct 2005 17:27 GMT getting .net to work with com is always difficult. javascript.net tries harder than most other .net languages, but still falls short. you should use the mshtml interop assembly (comes with 1.1), rather than having javascript.net dynamically try to figure out what to pass.
-- bruce (sqlwork.com)
>>> In any case I tried your suggestion >>> [quoted text clipped - 58 lines] > -- > Eugene Eugene Gershnik - 19 Oct 2005 18:04 GMT > getting .net to work with com is always difficult. javascript.net > tries harder than most other .net languages, but still falls short. > you should use the mshtml interop assembly (comes with 1.1), rather > than having javascript.net dynamically try to figure out what to pass. But I *am* using it! Look at the top error stack from the original post
... at mshtml.HTMLDocumentClass.write(Object[] psarray) ...
.NET automatically substitutes mshtml for the COM component probably because of the following entries under InprocServer32 in registry (also mentioned in more detail in one of the previous posts)
Assembly REG_SZ Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Class REG_SZ mshtml.HTMLDocumentClass RuntimeVersion REG_SZ v1.0.3705
It looks like whatever JScript.NET passes to mshtml is broken.
 Signature Eugene http://www.gershnik.com
Bruce Barker - 21 Oct 2005 21:37 GMT all languages have trouble calling this componenet. the actual com component is expecting a a safearray of olevariants. the interop is expecting a parm array of objects that can be convert to an olevariants (of type string).
try using a typed variable, so that javascript.net does not have to guess the datatype for the interop assembly.
var s : string = "abc"; doc.write(s);
or
doc.write(String("abc"));
-- bruce (sqlwork.com)
>> getting .net to work with com is always difficult. javascript.net >> tries harder than most other .net languages, but still falls short. [quoted text clipped - 17 lines] > > It looks like whatever JScript.NET passes to mshtml is broken. Eugene Gershnik - 22 Oct 2005 06:01 GMT > all languages have trouble calling this componenet. the actual com > component is expecting a a safearray of olevariants. the interop is > expecting a parm array of objects that can be convert to an > olevariants (of type string). Yes the following C# code has the same problem
using mshtml; ... HTMLDocumentClass doc = new HTMLDocumentClass(); doc.write("abc");
> try using a typed variable, so that javascript.net does not have to > guess the datatype for the interop assembly. If you look a few messages above in this thread you'll see that I already tried that (as well as other possible combinations) and it didn't work. Trying the same combinations in C# produced the same exception.
So it looks like mshtml wrapper is broken.
 Signature Eugene
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|