2012-03-15 24 views
4

私はいくつかのtrxファイル(webTestResults)を解析して、合成エクセルファイルを出力しようとしています。例外をスローするTestRunTypeのシリアライズ

まず、私はC#クラスの束を生成するために、trx xsdスキーマ(Visual Studioディレクトリ内のvstst.xsd)をとります。

次に、(スキーマから生成された)TestRunTypeの型に基づいてXmlSerializerをインスタンス化しようとします。

XmlSerializer xmlSer = new XmlSerializer(typeof(TestRunType)); 

のXmlSerializerのインスタンスは、例外が発生します:

System.InvalidOperationException: There was an error reflecting type 'TestRunType'. ---> System.InvalidOperationException: There was an error reflecting property 'Items'. ---> System.InvalidOperationException: There was an error reflecting type 'TestRunTypeTestDefinitions'. ---> System.InvalidOperationException: There was an error reflecting property 'Items'. ---> System.InvalidOperationException: There was an error reflecting type 'OrderedTestType'. ---> System.InvalidOperationException: There was an error reflecting type 'CodedWebTestElementType'. ---> System.InvalidOperationException: There was an error reflecting property 'Items'. ---> System.InvalidOperationException: Member 'CodedWebTestElementType.Items' hides inherited member 'BaseTestType.Items', but has different custom attributes. 
    at System.Xml.Serialization.StructMapping.FindDeclaringMapping(MemberMapping member, StructMapping& declaringMapping, String parent) 
    at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) 

カスタム属性は何ですか? だけBaseTestTypeの始まり:

public abstract partial class BaseTestType { 

    private object[] itemsField; 

    private bool enabledField; 

    private string idField; 

    private string nameField; 

    private bool isGroupableField; 

    private int priorityField; 

    private string namedCategoryField; 

    private string storageField; 

    public BaseTestType() { 
     this.enabledField = true; 
     this.isGroupableField = true; 
     this.priorityField = 2147483647; 
     this.namedCategoryField = ""; 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Agent", typeof(BaseTestTypeAgent))] 
    [System.Xml.Serialization.XmlElementAttribute("Css", typeof(BaseTestTypeCss))] 
    [System.Xml.Serialization.XmlElementAttribute("DeploymentItems", typeof(BaseTestTypeDeploymentItems))] 
    [System.Xml.Serialization.XmlElementAttribute("Description", typeof(object))] 
    [System.Xml.Serialization.XmlElementAttribute("Execution", typeof(BaseTestTypeExecution))] 
    [System.Xml.Serialization.XmlElementAttribute("Owners", typeof(BaseTestTypeOwners))] 
    [System.Xml.Serialization.XmlElementAttribute("Properties", typeof(BaseTestTypeProperties))] 
    [System.Xml.Serialization.XmlElementAttribute("TcmInformation", typeof(TcmInformationType))] 
    [System.Xml.Serialization.XmlElementAttribute("TestCategory", typeof(BaseTestTypeTestCategory))] 
    [System.Xml.Serialization.XmlElementAttribute("WorkItemIDs", typeof(WorkItemIDsType))] 
    public object[] Items { 
     get { 
      return this.itemsField; 
     } 
     set { 
      this.itemsField = value; 
     } 
    } 

そしてCodedWebTestElementType:

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://microsoft.com/schemas/VisualStudio/TeamTest/2010")] 
public partial class CodedWebTestElementType : BaseTestType { 

    private object[] itemsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("IncludedWebTests", typeof(CodedWebTestElementTypeIncludedWebTests))] 
    [System.Xml.Serialization.XmlElementAttribute("WebTestClass", typeof(CodedWebTestElementTypeWebTestClass))] 
    public object[] Items { 
     get { 
      return this.itemsField; 
     } 
     set { 
      this.itemsField = value; 
     } 
    } 
} 

誰かが、問題が何であるかを私に説明できますか?

おかげで...

答えて

8

ソリューションは、派生クラス(CodedWebTestElementTypeGenericTestType)からのアイテムプロパティを削除するには、だけでなく、シリアル化する場合には値を逃さないようにするために、基本クラスに属性を移動することですあなたコード化されたウェブテストまたはジェネリックテストがある。

IOWの場合、解決策は次のとおりです。

まず、それはBaseTestType基底クラスには2つのXmlElementAttribute属性(最後の2を参照)の動き、そして、CodedWebTestElementTypeタイプ

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://microsoft.com/schemas/VisualStudio/TeamTest/2010")] 
public partial class CodedWebTestElementType : BaseTestType { 
} 

からItemsプロパティを削除します。do、その後

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute("Agent", typeof(BaseTestTypeAgent))] 
[System.Xml.Serialization.XmlElementAttribute("Css", typeof(BaseTestTypeCss))] 
[System.Xml.Serialization.XmlElementAttribute("DeploymentItems", typeof(BaseTestTypeDeploymentItems))] 
[System.Xml.Serialization.XmlElementAttribute("Description", typeof(object))] 
[System.Xml.Serialization.XmlElementAttribute("Execution", typeof(BaseTestTypeExecution))] 
[System.Xml.Serialization.XmlElementAttribute("Owners", typeof(BaseTestTypeOwners))] 
[System.Xml.Serialization.XmlElementAttribute("Properties", typeof(BaseTestTypeProperties))] 
[System.Xml.Serialization.XmlElementAttribute("TcmInformation", typeof(TcmInformationType))] 
[System.Xml.Serialization.XmlElementAttribute("TestCategory", typeof(BaseTestTypeTestCategory))] 
[System.Xml.Serialization.XmlElementAttribute("WorkItemIDs", typeof(WorkItemIDsType))] 
[System.Xml.Serialization.XmlElementAttribute("IncludedWebTests", typeof(CodedWebTestElementTypeIncludedWebTests))] 
[System.Xml.Serialization.XmlElementAttribute("WebTestClass", typeof(CodedWebTestElementTypeWebTestClass))] 
public object[] Items 
{ 
    get { 
     return this.itemsField; 
    } 
    set { 
     this.itemsField = value; 
    } 
} 

GenericTestTypeクラスの場合と同じことです。

あなたがIncludedWebTestsWebTestClassコマンドまたはSummaryXmlFileノード1日を取得した場合に情報を失うことはありませんこの方法です。