locked
Unable to cast object of type 'HealthRecordItem' to type 'Microsoft.Health.ItemTypes.Medication' RRS feed

  • Question

  • Hi,

    I am getting exception " Unable to cast object of type 'Microsoft.Health.HealthRecordItem' to type 'Microsoft.Health.ItemTypes.Medication" while importing Medication  from healthvault. Previously it is working fine if we enter general information in health vault, the records are imported.

    This error comes when we enter all the fields in Advanced options and trying to import that Medication.
    Same exception is coming for Immunizations also. 


    I enabled Mdication ,Medication(V1) for Medications and Immunization,
    Immunization (V1) for Immunizations in application permissions.

    Kindly help me in this issue.


    Thanks in advance,
    Chellamnaidu
    Friday, October 23, 2009 12:34 PM

Answers

  • This is a common point of confusion. I suggest you read my post about versioning here.

    What is happening is that because you have authorized both versions of a type, the platform returns the instances in the record in either of those versions. Your code is looking for Medication, but it's coming back as MedicationV1. Because we don't register the old data types by default, that means you just see it as HealthRecordItem.

    The fix is to authorize only to the versions that your app is using, and let the HealthVault platform convert all instances to that version. In this case, it would mean authorizing only Medication and Immunization.

    Tuesday, October 27, 2009 5:27 PM

All replies

  • Hello Chellamnaidu,

    I think it will be easy to understand the issue if you can share us the code which is getting this error. Also please share your application ID.
    Also let me know from when you are getting this error?

    Thanks and Regards,
    Aneesh D.


    Friday, October 23, 2009 4:21 PM
  • Hi Aneesh,

       My ApplicationID is "6237e6d6-35d8-45ef-bbd0-6e445eea2837 " we are getting this error .

        This error comes after we enter all the fields in Advanced options and trying to import that Medication. This exception is coming from afternoon.

    One more Question is By Mistake I deleted the Application from Application configuration how to get back it?
    If i am trying to add the same from Application Manager it is giving error Application Id already Exists.

    Thank you
    Chellamnaidu
    Friday, October 23, 2009 4:41 PM
  • Normally changes in the configuration center takes half an hour to get reflected. Please try after half an hour to upload the certificate and let me know if you are still facing the issue.

    Regarding the error I am trying to reproduce the issue and will get back to you with the results as soon as possible.

    Thanks and Regards,
    Aneesh D.
    Friday, October 23, 2009 5:15 PM
  • Ok thanks Aneesh,

      I removed the Application Id from  "Application Configuration Center " almost 1 hour back. But still i am getting the error if i am trying to upload the certificate.

    Thanks and Regards,
     Chellamnaidu
    Friday, October 23, 2009 5:35 PM
  • Hello Chellamnaidu,

    I am not able to reproduce the issue in my sample application. Can you please share us the part of the code which is having this issue?

    Regarding the Application ID issue I have contacted our technical team. I will soon have an update on the same.

    Thanks and Regards,
    Aneesh D.
    Friday, October 23, 2009 6:18 PM
  • Check if this helps

    http://social.msdn.microsoft.com/forums/en-US/healthvault/thread/63ae6d79-cba1-4de1-aea6-bbd79f72e761/


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Friday, October 23, 2009 7:47 PM
  • Hi Rajesh,

    I placed the code in my global.asax page as you mentioned in the above link but it doesn't works for me.

    Here I am giving complete details.

    Application ID: "b3ef0579-3d88-4d61-b426-2132e049eff2 "

    I followed the following steps.

    In HealthVault PPE Environment(https://xray.getrealconsulting.com/") I tried to create a record in Immunization [ImmunizationV1]. I entered the Name "ChickenPox Vaccine" and entered all fields then i clicked on Create button and I got the following Error message

    "An error occurred while processing your request

    The error has been logged. If you continue to experience this error, please contact technical support.

    Error Message:Object reference not set to an instance of an object. "

    But when I go to my HealthVault account Ifound that a record was created in Immunizations category(i.e Exception occured but Immunization is created).

    Now when i tried to Synch with healthvault from my application, I am getting the following error message: "Unable to cast object of type 'HealthRecordItem' to type 'Microsoft.Health.ItemTypes.Immunization".

    I noticed the following things in
     
    In viewlatest items of https://xray.getrealconsulting.com in Immunizations " Microsoft.Health.HealthRecordItem " is coming in the "DisplayValue" Column instead of Immunization name.

    When I tried to edit, It shows the same exception which showed in creation. But when I edit it from my HealthVault account it is working fine.

    Here are the Immunization id's which are causing Exception:

    1) key.Id "26f36ad8-96d0-44a3-9119-a9e50ddf852f"   VersionStamp "218ee46e-3e11-4983-9899-2764ccf6845b"
    2) key.Id "56e07e19-519c-4e66-9bc0-aa5bc2016f20"   VersionStamp "682e9666-2e29-4b08-ad5b-aeefcdc93c7f"

    Code:
    foreach (HealthRecordItem item in items)
            {
                typedList.Add((T)item); //
    Code Causes Error
           
    }

    please guide me how to fix this as it is urgent for me.

    Thanks and Regards
    ChellamNaidu
    Tuesday, October 27, 2009 11:47 AM
  • Please try the fix posted here

    http://social.msdn.microsoft.com/Forums/en-US/healthvault/thread/c81728a2-fd1e-414b-97e1-c30490e1af81
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Tuesday, October 27, 2009 2:05 PM
  • This is a common point of confusion. I suggest you read my post about versioning here.

    What is happening is that because you have authorized both versions of a type, the platform returns the instances in the record in either of those versions. Your code is looking for Medication, but it's coming back as MedicationV1. Because we don't register the old data types by default, that means you just see it as HealthRecordItem.

    The fix is to authorize only to the versions that your app is using, and let the HealthVault platform convert all instances to that version. In this case, it would mean authorizing only Medication and Immunization.

    Tuesday, October 27, 2009 5:27 PM
  • Regarding the error on uploading a deleted application's ApplicationID to the configuration center again, a bug has been filed for the same.

    Thanks and Regards,
    Aneesh D.
    Wednesday, October 28, 2009 10:24 PM