tags:

views:

8

answers:

1

Hello!

I am trying to capture links that were added to a work item in TFS by catching WorkItemChangedEvent via TFS services. Here is the relevant XML part of the message that comes through:

<AddedRelations><AddedRelation><WorkItemId>8846</WorkItemId></AddedRelation></AddedRelations>

This is declared as a field in WorkItemChangedEvent class that should be deserialized into object upon receiving the event:

public partial class WorkItemChangedEvent
{
private string[] addedRelations;

/// <remarks/>
    [XmlArrayItemAttribute("WorkItemId", IsNullable = false)]
    public string[] AddedRelations
    {
        get { return this.addedRelations; }
        set { this.addedRelations = value; }
    }
}

I cannot for the life of me figure out why the AddedRelations does not get deserialized properly. I can only suspect that the object structure does not match the XML schema. Help would be appreciated.

A: 

I have changed the structure of my WorkItemChangedEvent class a little bit to match the XML:

public partial class WorkItemChangedEvent
{
private AddedRelation[] addedRelations;

/// <remarks/>
    [XmlArrayItemAttribute("AddedRelation", IsNullable = false)]
    public AddedRelation[] AddedRelations
    {
        get { return this.addedRelations; }
        set { this.addedRelations = value; }
    }

[GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [SerializableAttribute()]
    [DebuggerStepThroughAttribute()]
    [DesignerCategoryAttribute("code")]
    [XmlTypeAttribute(Namespace = "")]
    public partial class AddedRelation
    {
        #region Fields
        private string workItemId;
        #endregion

        /// <remarks/>
        public string WorkItemId
        {
            get { return this.workItemId; }
            set { this.workItemId = value; }
        }
    }
}

I still think that there must be some logic behind the original solution since it was designed by TFS authors (MS)? Anyway I am glad it works now and that I answered my question first ;]

dream3n