Ask a questionAsk a question
 

AnswerCustom data Type

  • Thursday, September 24, 2009 10:38 AMhibalina Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hey
    i created a custom type and register it in healthvault, i followed the code in msdn of CustomHealthTypeWrapper. adding a new item to HV is working, but when i get that item from HV this error appeared:

    Unable to cast object of type 'Microsoft.Health.ItemTypes.ApplicationSpecific' to type 'CustomHealthTypeWrapper'.

    Here is the code i used to get an item:

    Dim TYPE As Guid = New Guid(CustomHealthTypeWrapper.ApplicationCustomTypeID)
            Dim searcher As HealthRecordSearcher = Me.PersonInfo.SelectedRecord.CreateSearcher()
            Dim filter As HealthRecordFilter = New HealthRecordFilter()
            filter.TypeIds.Add(TYPE)
            filter.XPath = Incident.XPathFilterForQuery
            searcher.Filters.Add(filter)
            Dim objincident As New Incident

            Dim items As HealthRecordItemCollection = searcher.GetMatchingItems(0)
            For Each item As HealthRecordItem In items
                Dim obj As New CustomHealthTypeWrapper
                obj = DirectCast(item, CustomHealthTypeWrapper)
            Next

    the error appeared when trying to cast from item to CustomHealthTypeWrapper

    thanks

Answers

  • Thursday, September 24, 2009 2:38 PMEric GunnersonMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Did you call RegisterTypeHandler() on your class? If not, the SDK doesn't know how to create your class. Something like:

    ItemTypeManager.RegisterTypeHandler(new Guid("a5033c9d-08cf-4204-9bd3-cb412ce39fc0"), typeof(CustomHealthTypeWrapper), true);

    (translated to VB, of course...)

All Replies

  • Thursday, September 24, 2009 2:38 PMEric GunnersonMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Did you call RegisterTypeHandler() on your class? If not, the SDK doesn't know how to create your class. Something like:

    ItemTypeManager.RegisterTypeHandler(new Guid("a5033c9d-08cf-4204-9bd3-cb412ce39fc0"), typeof(CustomHealthTypeWrapper), true);

    (translated to VB, of course...)
  • Thursday, September 24, 2009 5:30 PMlinaB Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    thanks
    i did it and it works now