views:

68

answers:

1

Am in process of building my custom component. Am trying to read values of PipleBuffer by GetProperty("propertyname").GetValue() as below:

    public override void ProcessInput(int inputID, PipelineBuffer buffer)
    {
        while (buffer.NextRow())
        {
            string nk = buffer[1].ToString();
            string nk1 = buffer.GetType().GetProperty("NK").GetValue(buffer, null).ToString();

at line buffer[1].ToString() work fine, but at next line it fails throwing :

NullReferenceException : object reference not set to an instance of an object

Any clues please.

Cannot create object instance of PipleBuffer as is under protection level.

A: 

Either buffer.GetType().GetProperty("NK") is null, or buffer.GetType().GetProperty("NK").GetValue(buffer, null) is null.

Change your code as follows and find out:

PropertyInfo prop = buffer.GetType().GetProperty("NK");
if (prop == null)
{
    throw new Exception("prop is null!");
}

object value = prop.GetValue(buffer, null);
if (value == null)
{
    throw new Exception("value is null!");
}

string nk1 = value.ToString();

Note this is for diagnostic purposes only. I don't propose you keep this in your code!

John Saunders