I have not been able to get an error message by updating a field in a struct which is an array in another struct. If you would like me to take a look at this please send a reproducible sample to vstasupport@summsoft.com .
Here are my findings:
1) Passing a struct containing an array of structs and passing an array of structs.
I added the following classes to the ShapeAppBasicCSharp sample:
[Serializable]
public struct OutterStruct
{
private string Oname;
public string OName
{
get { return Oname; }
set { Oname = value; }
}
private int Oid;
public int OId
{
get { return Oid; }
set { Oid = value; }
}
private InnerStruct[] sarray;
public InnerStruct[] Sarray
{
get { return sarray; }
set { sarray = value; }
}
}
[Serializable]
public struct InnerStruct
{
private string Iname;
public string IName
{
get { return Iname; }
set { Iname = value; }
}
private int Iid;
public int IId
{
get { return Iid; }
set { Iid = value; }
}
}
I also added a property of type OutterStruct and methods to create instances of the inner and outter struct.
I added a method which takes in an OutterStruct and alters the name and id properties, then alters the name and id properties of the array of InnerStructs. What I found is that the outter struct properties name and id behave as if they are passed by value, when the method is exited those properties revert to their original values. However, the array of structs behaves as if it is passed by reference, when the method is exited the properties of the structs in the array do not revert to their original values. This behavior is consistent- calling the method from an add-in has the same affect on the OutterStruct passed in as if it were called by the host.
I also added a method which takes in an InnerStruct[] and alters the name and id properties of each struct in the array. What I found is that when this method is called from VSTA the array of structs behaves as if it is passed by value, the values of the properties of the structs in the array revert back to their original values when the method is exited. However, when this method is called from within the host the array of structs behaves as if it is passed by reference, the values of the properties of the structs in the array do not revert back to their original values when the method is exited. VSTA should behave in the same way that Visual Studio does and behave as if it passes the array of structs by reference, not value. This is due to a problem with the equals and get has code methods and I believe there is a work around.
2) Updating information in a struct and in a struct which is in an array of structs within a struct
I added a method which sets a local variable (LoS) of type OutterStruct to the property oStruct (property of the application class, type OutterStruct). When a property like name or id is changed, it behaves as if it is changed by value- changing the variable LoS doesn't affect the property oStruct and changing the property oStruct does not change the variable LoS. However, changing a property of a struct in the array of structs within the outter struct behaves as if it is by reference- changing the value of the name or id of a struct in the array of structs in the variable LoS does change the property of the struct in the array of struts in oStruct and vice versa. In VSTA, (also using a local variable LoS) the by value property changes (of properties like name and id) reflect the way Visual Studio handles this- by value. However, the changing a property of a struct in the array of structs in the outter struct doesn't work. The property in the struct in the array of structs in the outter struct does not change in the local variable or the application property. This is due to a problem with the equals and get hash code methods and I believe there is a work around.
>am also concerned that field updates to the structure are remoted.
In VSTA v 1, everything exists on the host side therefore everything is remoted. VSTA v 2 handles structs completely differently. I will look into this issue in VSTA v 2 and let you know what I find.
If you would like to see the modified shape app sample I based these findings are please e-mail me at VSTASupport@summsoft.com and I will get you a copy.