?
Solved

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

Posted on 2013-01-24
2
Medium Priority
?
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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