DynamicObject.GetDynamicMemberNames() exception
Let me try this again. Please don't move this post - I'm posting in the C# language group that is listed under VS 2010 Beta 2 forums.
I've overriden this method to return runtime member info but when I look at the info in the data tip, it displays a System.SystemException with the message:
{"The result of the dynamic binding produced by the object with type 'Foo' for the binder 'Microsoft.CSharp.RuntimeBinder.GetMemberValueBinder' needs at least one restriction."}
What's up with this error? I've tested the code in the constructor and verified that it works.
Also, it would be much more useful if this information were actually available during editing so you could get Intellisense. Yes, I know this would require instantiating the object so it could query this member. Perhaps this would be a DynamicObject property (SupportsDesignTime) that is false by default. BTW to get even better Intellisense support there should be a GetDynamicMemberParameters() method that provides parameter and return type information.
Answers
- I recently wrote a blog post that basically shows the same example: a wrapper for XElement by using DynamicObject. You can take a look here: http://blogs.msdn.com/csharpfaq/archive/2009/10/19/dynamic-in-c-4-0-creating-wrappers-with-dynamicobject.aspx
I did not use the GetDynamicMemberNames() there. However, this is for C# users, not for dynamic languages like Python. But it may help you anyway.
Looks like you have some kind of advanced scenario. I'd recommend you to take this question to the DLR team.
You can ask questions here: http://dlr.codeplex.com/Thread/List.aspx
Or you can write an email to dlr@microsoft.com
But you will probably need to show the actual code there.- Marked As Answer byJi.ZhouMSFT, ModeratorMonday, November 09, 2009 3:33 AM
All Replies
Hello Keith,
Do you mean you can compile and run your codes correctly, but from the IDE (data tip), the exception is thrown? What do you mean about the data tip. What are your codes? Could you please elaborate a little more about the issue? :-)
Have a nice day!
Ji Zhou
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Yes, the code compiles and runs but when I go to expand the DynamicMembers property for an instance of the object in the debugging data tip, I get the following error in a dlg box:
{"The result of the dynamic binding produced by the object with type 'Foo' for the binder 'Microsoft.CSharp.RuntimeBinder.GetMemberValueBinder' needs at least one restriction."}
--
Keith - Hi Keith.
Can you tell me a little bit more about your use case and show some code example?
As far as I know, you are not supposed to override this method at all unless you have some really rare scenarios. This method is now only used by DLR for debugging purposes. I suggest you to create a method with a different name instead of overriding this one. - I was reading a draft of a book covering C# 4.0 and it gives an example of using GetDynamicMemberNames to return the list of XElement names for a DynamicObject implementation that wraps an XML file. The idea was that REPL environments like Python can query the member names to provide Intellisense. I get this feature all the time in PowerShell where, if I have created the object, PoweShell can reflect upon the instance and provide Intellisense. If these environments encounter a DynamicObject instancen then clearly the data return via reflection isn't that useful. I thought GetDynamicMemberNames() was the way I could write my object to interact better in these other REPL environments.
BTW the Intellisense capability *could* be made available in C# - in theory. The C# compiler,while doing a background compile, would need to create an instance of the object - or better yet - create an instance of a metaobject ie an object that *just* describes the runtime type info for the dynamic object. This metaobject should have no destructive side effects but it probably would need some extra info. Like the XML wrapper would need the path to the XML file. Plus to get a really good Intellisense experience the DynamicObject (or metaobject) needs to be able to return much richer info: member description, parameter information, parameter description, return type, etc. - I recently wrote a blog post that basically shows the same example: a wrapper for XElement by using DynamicObject. You can take a look here: http://blogs.msdn.com/csharpfaq/archive/2009/10/19/dynamic-in-c-4-0-creating-wrappers-with-dynamicobject.aspx
I did not use the GetDynamicMemberNames() there. However, this is for C# users, not for dynamic languages like Python. But it may help you anyway.
Looks like you have some kind of advanced scenario. I'd recommend you to take this question to the DLR team.
You can ask questions here: http://dlr.codeplex.com/Thread/List.aspx
Or you can write an email to dlr@microsoft.com
But you will probably need to show the actual code there.- Marked As Answer byJi.ZhouMSFT, ModeratorMonday, November 09, 2009 3:33 AM


