tukarambande / xmlrpcnet

Automatically exported from code.google.com/p/xmlrpcnet
0 stars 0 forks source link

Interface cannot contain object that contains array of objects of this same type. Including them leads to stack overflow. #70

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create class, whose one property is list of objects of this class. For
example:

public class Example
{
    public Example[] ChildExamples;
}

2. Create XmlRpcMethod that uses this class (either as input parameter, or
as return value)
3. Run the XmlRpcService => The service cannot be called, because it fails
on StackOverFlowException

What is the expected output? What do you see instead?
- expected output: No StackOverFlowException is thrown, service can be called

What version of the product are you using? On what operating system?
- we are using xml-rpc.net.2.4.0; Operating system Windows XP, .NET 2.0

Please provide any additional information below.

The problem happens in class XmlRpcServiceInfo, method GetXmlRpcType.

The problem is that validation calls this same method (GetXmlRpcType) on
all type members. However, when the type member is 'Array', it calls the
method on elements of this array. This leads to stack overflow, because the
methods get called endlessly like this:

 1. GetXmlRpcType(typeof(Example))
 2. GetXmlRpcType(typeof(Array of Example))
 3. GetXmlRpcType(typeof(Example))
 etc.

We have fixed the issue temporarily for our project like this (see method
GetXmlRpcType, almost at the end):
        MemberInfo[] mis = t.GetMembers();
        foreach (MemberInfo mi in mis)
        {
            if (mi.MemberType == MemberTypes.Field)
            {
                FieldInfo fi = (FieldInfo)mi;
                //rudepeklo start - check for elements of the array. If
they are of same type,
                //do not validate
                if (fi.FieldType.IsArray)
                {
                    if (fi.FieldType.GetElementType() == t)
                        continue;
                }

                //rudepeklo end
                if ((fi.FieldType == t) || (fi.FieldType != typeof(Object)
                  && GetXmlRpcType(fi.FieldType) == XmlRpcType.tInvalid))
                {
                    return XmlRpcType.tInvalid;
                }
            }
            else if (mi.MemberType == MemberTypes.Property)
            {
                PropertyInfo pi = (PropertyInfo)mi;
                if ((pi.PropertyType == t) || (pi.PropertyType !=
typeof(Object)
                  && GetXmlRpcType(pi.PropertyType) == XmlRpcType.tInvalid))
                {
                    return XmlRpcType.tInvalid;
                }
            }
        }

Original issue reported on code.google.com by rudepe...@gmail.com on 17 May 2010 at 10:06

GoogleCodeExporter commented 8 years ago
Fixed in revision 118.

Original comment by ChasC...@gmail.com on 22 May 2010 at 3:35