سؤال

This is my code in the webservice

private object[] _myObjectVariableList = new object[7];

public object[] MyObjectVariableList
{
    get { return _myObjectVariableList; }
    set { _myObjectVariableList = value; }
}

and when I pass a value to it using

 AuditTrail auditclass = new AuditTrail();
 auditclass.MyObjectVariableList[indexCounter] = myTextBox.Text;

I receive an error

Object reference not set to an instance of an object.

I really do not know whats happening

Any ideas?

هل كانت مفيدة؟

المحلول

you need to initialize the list in client side

AuditTrail auditclass = new AuditTrail(); 

auditclass.MyObjectVariableList = new object[7];

or in service class constructor initialize the property value

public class AuditTrail 
{
    private object[] _myObjectVariableList;

    public object[] MyObjectVariableList
    {
        get { return _myObjectVariableList; }
        set { _myObjectVariableList = value; }
    }
    public AuditTrail()
    {
        MyObjectVariableList= new object[7];
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top