0

I am new to C Sharp programming. I am getting the error.

Script Component has encountered an exception in user code: Object reference not set to an instance of an object. at ScriptMain.Input0_ProcessInputRow(Input0Buffer Row) at UserComponent.Input0_ProcessInput(Input0Buffer Buffer) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)

This is my code as follows

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;


[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        int iEx = 0;
        int iPr = 0;
        int iPa = 0;
        int iSch = 0;
        int iTim=0;
        int iTime = 0;
        int tryCount=1;
        SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Service s = new SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Service();
        SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.LicenseUsage[] l = SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.LicenseUsage[10];
        l =null;
        while (tryCount<=3)
        {
            try
            {   l = s.GetProductPeakUsage(Row.salesforceidstring, Row.StartDatestring, Row.EndDatestring);
                break;
            }
            catch (Exception e)
            {
                tryCount = tryCount + 1;
                if (tryCount > 3)
                {
                    bool pbCancel = false;
                    this.ComponentMetaData.FireError(9999, "Error-Failed the 3rd time", e.ToString(), "", 0, out pbCancel);
                }

            }
        }

        for (int i = 0; i < l.Length; i++)
        {
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Pr)
                iPr = l[i].ActiveSeats;
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Sch)
                iSch = l[i].ActiveSeats;
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Pa)
                iPa = l[i].ActiveSeats;
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Ex)
                iEx = l[i].ActiveSeats;
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Time)
                iTime = l[i].ActiveSeats;
            if (l[i].Product == SC_819162ba1fcf40f686f8181327002472.csproj.WebReference.Product.Tim)
                iTim = l[i].ActiveSeats;
        }
        Row.Ex = iEx;
        Row.Pr = iPr;
        Row.Sch = iSch;
        Row.Pa = iPa;
        Row.Time = iTime;
        Row.Tim=iTim;

    }

}

Can somebody help how should I debug this? I understand I am getting null values for inputs. How to bypass null values in this logic

billinkc
  • 59,250
  • 9
  • 102
  • 159
Karthi
  • 708
  • 1
  • 19
  • 38
  • 3
    [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Oct 20 '15 at 12:35
  • I edited the above code and am still getting the same issue. I have initialized the object and then assigned the null value.. Any help on this? – Karthi Oct 20 '15 at 14:08
  • Set breakpoints and find exactly which lines cause you trouble. To check for null, you can try `if (myObj == null) { doThisNotThat(); }`. – sorrell Oct 20 '15 at 16:51
  • Test any object (`row` & `s` for example) to verify they are not null before attempting to do anything with them. – Tab Alleman Oct 20 '15 at 20:20
  • Assuming I didn't break anything as I was formatting, you have an array, `l` that you assign to an array instance of size 10 but you never call `new` there. You then immediately assign l back to null. So, that's a good opportunity for your NullReferenceException – billinkc Oct 22 '15 at 02:50

0 Answers0