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?
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?