Solved

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

Posted on 2013-01-24
2
514 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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