Solved

array of classes and setting property on class gives me a nullexception

Posted on 2013-01-24
2
508 Views
Last Modified: 2013-01-25
I have a method on wcf service and throws a nullexception when I try to assign a value to a property on my class. Here is my method code.

The data comes back from my call to my business object, and I can see the records in the list, what I am trying to do is build out the array, unless there  anyone knows of a different way to handle this. As I just want to call this and return a json object of my results.

 public PatientRecords[] GetPatientName()
        {

            //Will pull back the patient list for the careplans that belong to the site.
            Patients patient_data = new Patients();
            IList<sidwservices.sidw_ef.patient> ReturnValue = patient_data.GetPatientList();
            //Free that object
            patient_data = null;
            PatientRecords[] returns = new PatientRecords[ReturnValue.Count];
            int x = 0;
            for (int i = 0; i < ReturnValue.Count; ++i)
            {
                //Log error message
                ErrorHandler.LogElmahMessage("GetPatientName1", "SidwServices-Careplan");
                //Free error handler object
                ErrorHandler = null;

                //FAILS HERE WITH A NULL EXCEPTION
                returns[x].id = ReturnValue[i].id;
                returns[x].mrn = ReturnValue[i].mrn;

                //Log error message
                ErrorHandler.LogElmahMessage("GetPatientName3", "SidwServices-Careplan");
                //Free error handler object
                ErrorHandler = null;
                x = x + 1;
                
            }
            //Log error message
            ErrorHandler.LogElmahMessage("GetPatientName", "SidwServices-Careplan");
            //Free error handler object
            ErrorHandler = null;
            return returns;
        }

Open in new window


Class code
   [DataContract]
    public class PatientRecords
    {
        [DataMember]
        public long id
        {
            get;
            set;
        }

        [DataMember]
        public long site_id
        {
            get;
            set;
        }

        [DataMember]
        public string mrn
        {
            get;
            set;
        }


        //[DataMember]
        //public long pat_seqno
        //{
        //    get;
        //    set;
        //}

        //[DataMember]
        //public string first_name
        //{
        //    get;
        //    set;
        //}

        //[DataMember]
        //public long last_name
        //{
        //    get;
        //    set;
        //}

        //[DataMember]
        //public DateTime dob
        //{
        //    get;
        //    set;
        //}
    }
 

Open in new window

0
Comment
Question by:JDEE8297
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 150 total points
ID: 38815304
try with:

returns[x] = new PatientRecords();   <------ add this line
returns[x].id = ReturnValue[i].id;
returns[x].mrn = ReturnValue[i].mrn;

Open in new window

0
 

Author Closing Comment

by:JDEE8297
ID: 38818280
thank you, that is what I get for being a c# newbie :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now