-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Object doesn't support this property or method" with VBScriptEngine #386
Comments
We tested your sample code and observed the following:
All of the observed behavior seems correct. Would you mind retesting? Are you still seeing "Object doesn't support this property or method" errors? Do the modifications above work for you? Thanks! |
In Visual Studio 2022, I created two projects, one in C# and one in VB.NET (thinking there could be a difference) with the following:
Both projects give me the same exception (Object doesn't support this property or method: cat.Kingdom). Here's the entire code I have been testing with: C# Program.cs
VB.NET ApplicationEvents.vb:
Ultimately I have been trying to work around the difference in Enum properties compared to MSScriptControl. With MSScriptControl, enums seem to be handled as their Integer value and that's where my scripts have been causing Type Mismatch errors with ClearScript. Your answer has been helpful in understanding how Enums are handled so I will try to adjust my scripts but it sounds like having scripts compatible with both ClearScript and MSScriptControl is not going to be possible. My goal is to move away from MSScriptControl so backwards-compatibility is not a problem. I am going to close this ticket because you have answered my question but I wanted to provide the complete code that caused the exception in case someone else runs into the same issue. |
That's correct. ClearScript doesn't convert enums to integers, because such conversion is lossy. One potential problem is that it could break method invocation. For example, consider the following .NET method: public void Foo(Kingdom arg) { ... } If ClearScript converted enums to integers, a call such as public void Foo(Kingdom arg) { ... }
public void Foo(SomeOtherEnum arg) { ... }
public void Foo(int arg) { ... }
Well, not exactly. You have control over what you expose to the script engine. If strongly typed enums are a problem in your scenario, you could expose a facade that uses integers instead. Please feel free to reopen this issue if you have additional questions or thoughts about this topic. Good luck! |
I ran into the "Object doesn't support this property or method: cat.Name" issue again as I was upgrading my scripts. In a separate .NET application I have a function that returns an object or Nothing. I am able to deal with the Nothing value using what was explained in issue #106. When I detect that the function has returned Nothing, I want to use another function to create the object. When I try accessing properties on the object the second function returns, I get the same problem where it doesn't recognize the object's properties. Here is some code that should replicate this problem:
I've added a Creator class from which I want to create new objects and use them on the script side:
|
Hello @EtienneLaneville,
That's because "creator" actually refers to the Here's what's going on. Your setup code includes the following: host.AddHostType(typeof(Creator));
// other code
host.AddHostObject("creator", creator); These lines create two host items: The script code above doesn't actually use Cheers! |
Thanks for your response. I've removed the line that add the Creator type to the engine but I am not getting any further, I get the same Object doesn't support this property or method: creator.CreateBeing exception. Here are the steps that I take, hopefully something here will stand out:
To eliminate any system specific differences, I have tried these steps using Hyper-V with the Windows 11 dev environment image and I see the same problem there. |
Figured out the problem: The code doesn't work when it is in the
|
Ah, yes. Member visibility enforcement is often the hidden cause of such issues. Thanks for posting the solution! |
I've been troubleshooting a Type Mismatch exception when trying to use object properties that are enums with VBScript. In trying to reproduce this, I started with the following enum and class (from another ticket):
Then, I created a VBScriptEngine instance to check if I can access the Being.Kingdom property:
The first Execute (MsgBox "Test" but the next one (MsgBox cat.Name) throws an exception:
Object doesn't support this property or method: cat.Kingdom
For reference, this is the HostWindow class used:
Originally posted by @EtienneLaneville in #156 (comment)
The text was updated successfully, but these errors were encountered: