Bug 576128

Summary: [DBus] Can't send struct as object over dbus
Product: [Mono] UI Automation Reporter: Rui Guo <rguo>
Component: Client - UIAAssignee: E-mail List <mono-a11y-bugs>
Status: NEW --- QA Contact: E-mail List <mono-a11y-qa>
Severity: Normal    
Priority: P5 - None CC: mgorse
Version: Unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Rui Guo 2010-02-02 13:55:11 UTC
E.g. in our UiaDbus code,
we have:

[Interface (Constants.ApplicationInterfaceName)]
public interface IApplication
{
...
	event AutomationPropertyChangedHandler AutomationPropertyChanged;
...
}

where AutomationPropertyChangedHandler is:
	public delegate void AutomationPropertyChangedHandler (int handlerId, int eventId, string providerPath, int propertyId, object oldValue, object newValue);

And we  also have a normal struct named Rect.
Then if we fire the event with following code:
	Rect r = new Rect (10.0, 10.0);
	AutomationPropertyChanged (123, 123, "path", 123, r, r);
The event singal will never reach the remote end.
However if we fire the event with these code:
	var r = new double [] { 10.0, 10.0 };
	AutomationPropertyChanged (123, 123, "path", 123, r, r);
The event singal will be sent to the remote end w/o any problem.

I expect the 1st case can work as well as the 2nd case.
Comment 1 Sanford Armstrong 2010-02-22 15:16:38 UTC
This may be fixed since we started using ndesk-dbus from git master.
Comment 2 Michael Gorse 2010-02-22 19:42:46 UTC
from http://www.ndesk.org/DBus_Documentation#D-Bus_variants:

   New feature in git as of March 2009: If it is not possible to determine the managed equivalent (for example if the received variant contains an anonymous structure, the
   type and fields of which are unknown), an opaque boxed object is returned. This object may be converted to its actual type, say a managed struct, array or IDictionary<,>,
   using System.Convert at any later point:
object boxedVariant = demo.ComplexAsVariant ();
MyStruct actualStruct = (MyStruct)Convert.ChangeType (boxedVariant, typeof (MyStruct));

   If MyStruct cannot represent boxedVariant, Convert.ChangeType() will safely throw an InvalidCastException.

   There is currently no official way to determine the signature of the received boxed variant, as the receiver will typically already know what format to expect based on an
   enum or string value in that call. Unofficially, ToString() may return the D-Bus signature of the variant as a string which can be helpful when dealing with poorly
   designed D-Bus interfaces from third parties. However, we recommend that developers treat the boxed opaque object as a strictly sealed and private object, only accessing
   it with System.Convert.
Comment 3 Sanford Armstrong 2010-02-24 19:13:19 UTC
I think we need to test this.  When the struct we're talking about is managed, perhaps these issues don't apply.