Error: System.Reflection.TargetInvocationException

  • hi guys

    please help me with my package, its a very simple package which emails supplier when the work order reaches a certain status. i've created an oledb source and connected to a RecordSet Destination.

    then i created a foreach loop container and selected Foreach ADO Enumerator with ADO object source vairable User:dsWorkOrders.

    i've also mapped variables:

    User::WOID

    User::WOCode

    User::SectionCode

    User::RequisitionNo

    User::WOSuppierCode

    User::EmailToName

    User::EmailToAddress

    User::EmailInvalid

    Then i created a script task with the following ReadOnlyVariables: User::EmailInvalid,User::EmailToAddress,User::EmailToName,User::RequisitionNo,User::SectionCode,User::WOCode,User::WOSupplierCode

    ReadWriteVariables: User::EmailMessage,User::EmailSubject:

    the following script below is built in my script task to creating the email message and email subject:

    public void Main()

    {

    // TODO: Add your code here

    string inv;

    bool PackageError = false;

    inv = Dts.Variables["EmailInvalid"].Value.ToString();

    if (inv == "V")

    {

    PackageError = false;

    Dts.Variables["EmailSubject"].Value = "Pragma Approved Invoice. " + Dts.Variables["SectionCode"].Value.ToString() +

    " - " + Dts.Variables["RequisitionNo"].Value.ToString() + " " + Dts.Variables["WOCode"].Value.ToString();

    Dts.Variables["EmailMessage"].Value = "Automated email per invoice pack";

    }

    if (inv == "I")

    {

    PackageError = true;

    Dts.Variables["EmailSubject"].Value = "Automated email notification of invoice submission for work order " + Dts.Variables["WOCode"].Value + " failed";

    Dts.Variables["EmailMessage"].Value = "The email address specified in On Key (" + Dts.Variables["EmailToAddress"].Value + ") is incorrect. " +

    "Please correct this in order for the email to be sent.\r\r" +

    "Note: if this email should be sent to more than one recipient, please seperate the email addresses by a ';' and no spaces " +

    " (example: test@pragmaworld.net;test2@pragmaworld.net).\r\r" +

    "Regards \r\r";

    }

    Dts.Variables["PackageError"].Value = PackageError;

    Dts.TaskResult = (int)ScriptResults.Success;

    }

    }

    my package fails in the script task, with the error 'Error: System.Reflection.TargetInvocationException'

    Please help.

    and apologies with the descriptive details.

  • Have you tried putting a breakpoint in the script task and then stepping through it line by line to determine exactly which row is generating the error? Might help you target the problem.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • thank you Phil for the quick response

    i've managed to find the error after going through my script task over and over again and found that i didn't assign the variable user::PackageError in the ReadOnlyVariable..

    thank you again.

  • Nomvula (11/17/2013)


    thank you Phil for the quick response

    i've managed to find the error after going through my script task over and over again and found that i didn't assign the variable user::PackageError in the ReadOnlyVariable..

    thank you again.

    No problem and good news that you've solved it!

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply