Completed
Last Updated: 19 Dec 2013 16:21 by ADMIN
ADMIN
Plamen
Created on: 08 Feb 2013 18:02
Type: Bug Report
0
InvalidOperationException when trying to serialize object of TestResult type.
Even the TestResult class has "Serializable" attribute that indicates that the class can be serialized, when initializing a new instance of the XmlSerializer class by passing the TestResult class as type argument, the following code throws InvalidOperationException.

XmlSerializer ser = new XmlSerializer(typeof(TestResult));


Failure Information: 
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[WebTest1_CodedStep1] : @"New Coded Step'.
InnerException:
System.InvalidOperationException: There was an error reflecting type 'ArtOfTest.WebAii.Design.Execution.TestResult'. ---> System.InvalidOperationException: There was an error reflecting property 'Parent'. ---> System.InvalidOperationException: There was an error reflecting type 'ArtOfTest.WebAii.Design.Execution.RunResult'. ---> System.NotSupportedException: Cannot serialize member ArtOfTest.WebAii.Design.Execution.RunResult.DataCollectors of type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary.
   at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo)
   at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
   at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
   at System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo)
   at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)
   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type)
   at TestStudioProject7.WebTest1.ReadTrxFileContents(String filePath) in C:\Users\peykov\documents\visual studio 2010\Projects\TestStudioProject7\TestStudioProject7\WebTest1.tstest.cs:line 80
   at TestStudioProject7.WebTest1.WebTest1_CodedStep1() in C:\Users\peykov\documents\visual studio 2010\Projects\TestStudioProject7\TestStudioProject7\WebTest1.tstest.cs:line 91
1 comment
ADMIN
Pavel Kotsev
Posted on: 22 Feb 2013 13:49
The .trx file does not contain enough information to deserialize to a TestResult object. A .trx file could be created as a result of a test run but it contains mainly a flat log and no metadata required to build up the whole TestResult object back.

The exception is caused by the fact that a XmlSerializer cannot create an object that contains Dictionary as one of its fields. TestResult contains a property named Parent that is of type RunResult. RunResult has a property named DataCollectors that is of type Dictionary<string, string> and thus the exception is thrown.