...may not be used in this context...while serialization

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-04-28T14:14:48Z Indexed on 2010/04/28 14:23 UTC
Read the original article Hit count: 257

Filed under:
|
|

Hi,

I've webservice and WebMethod

[webMethod]
public object GetObjects(Cars[] cars)
{
return Translator.ToObjects(Facade.GetObjects(cars);

}

public static object GetObjects(Cars cars)
{
List<Car>  cars =new List<Country(...fillingcollection)
return cars.ToArray(),
}

public static object ToObjects(object collection)
{
if(collection is Car[])
{
return ConvertModelCarsToContractCars(collection),
}

public ModelCar[]  ConvertModelCarsToContractCars(Cars[] collection)
{
...there is rewriting pool...
}

And I get exception at side of client:

There was an error generating the XML document.

I'm using this function to check collection which I would send to the client and it works, doesn't return exceptions:

 public static void SerializeContainer(object obj)
        {
            try
            {
                // Make sure even the construsctor runs inside a
                // try-catch block
                XmlSerializer ser = new XmlSerializer(typeof(object));

                TextWriter w = new StreamWriter(@"c:\list.xml");


              ser.Serialize(w, obj);
                w.Close();

            }
            catch (Exception ex)
            {
                DumpException(ex);
            }
        }

Interesting is when collection has only One element [webmethod] works fine, but when is more it brokes

© Stack Overflow or respective owner

Related posts about c#

Related posts about serialization