Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: Put Property Bug [104]

$
0
0
Setting a Value to Put Property outside the Script execution context fails, saying member not found.

here is a simple demonstration code:

```
var e = new VBScriptEngine();
e.Execute(@"
class test
private var_

public property get var
var = var_
end property
public property let var(val)
var_ = val
end property

Private Sub Class_Initialize()
var_ = ""value""
End Sub

end class
dim mytest : set mytest = new test
");
dynamic a = e.Script.mytest;
Console.WriteLine(a.var);

a.var = "adad"; // !! this used to fail also, but found a quick workaround. see code below
Console.WriteLine(a.var);

var e2 = new VBScriptEngine();
e2.Execute("dim mytest, tyna");
e2.Script.mytest = a;

e2.Execute("tyna = typename(mytest)");
e2.Execute("mytest.var = \"sad\""); // !! this fails !!
```


the quick fix is achived in COMDispatchHelper.cs inside the SetProperty(..) method, simply trying next DispatchFlags:

```
Marshal.ThrowExceptionForHR(result);
using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
{
using (var namedArgDispidBlock = new CoTaskMemBlock(sizeof(int)))
{
EXCEPINFO excepInfo;
Marshal.WriteInt32(namedArgDispidBlock.Addr, SpecialDispIDs.PropertyPut);
var dispArgs = new DISPPARAMS { cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 1, rgdispidNamedArgs = namedArgDispidBlock.Addr };
try
{
dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut | DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
return true;
}
catch (COMException)
{
try
{
dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPut, ref dispArgs, IntPtr.Zero, out excepInfo);
return true;
}
catch (COMException)
{
try
{
dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyPutRef, ref dispArgs, IntPtr.Zero, out excepInfo);
return true;
}
catch (COMException) { }
}
}
return false;
}
}
```

any ideas of why this happens at all?
Comments: Thanks for reporting this issue! To be honest, we haven't done much with VBScript recently beyond the coded tests in the project. It looks like VBScript class objects are unforgiving when it comes to those invocation flags, behaving quite differently from native JScript objects. We'll post a fix shortly (for both of the failure scenarios you've identified), as well as a few new tests. Thanks again!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images