"Runtime error Exception has been thrown by the target of an invocation" from Script task

perplexedDev picture perplexedDev · Mar 11, 2015 · Viewed 70.4k times · Source

I have a SSIS package with a script task, I get the following error when i try to run it in my local system. It works fine for my collegues as well as in production. However, I am not able to run it locally, to test. I keep a debug point in the main method, but it is never reached, I get the error before it goes to main method.

enter image description here

I am using VS 2010, .Net framework 4.5.

The script task does compile. I get the following messages SSIS package "..\Test.dtsx" starting. Error: 0x1 at Test: Exception has been thrown by the target of an invocation. Task failed: Test SSIS package "..\Test.dtsx" finished: Success. The program '[2552] DtsDebugHost.exe: DTS' has exited with code 0 (0x0).

The following is the code:

public void Main()
{
try
{
 LogMessages("Update Bug package execution started at :: " + DateTime.Now.ToLongTimeString());
 LogMessages("Loading package configuration values to local variables.");

strDBConn = Dts.Variables["User::DBConnection"] != null ? Dts.Variables["User::DBConnection"].Value.ToString() : string.Empty;
strTPCUrl = Dts.Variables["User::TPCUrl"] != null ? Dts.Variables["User::TPCUrl"].Value.ToString() : string.Empty;

TfsTeamProjectCollection objTPC = new TfsTeamProjectCollection(new Uri(strTPCUrl));
WorkItemStore objWIS = new WorkItemStore(objTPC);
WorkItemCollection objWIC = objWIS.Query("SELECT...");

foreach (WorkItem wi in objWIC)
{
}

}
catch(Exception ex)
{
}

When I commented the code from TfsTeamProjectCollection objTPC = new TfsTeamProjectCollection(new Uri(strTPCUrl)); The script executes successfully. However, if i keep TfsTeamProjectCollection objTPC = new TfsTeamProjectCollection(new Uri(strTPCUrl)); and comment the rest, i get the exception. I do have access to the URL.

I am using Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.WorkItemTracking.Client.dll, in my script task. However the dll version in the package is 10.0, and the version of the dll in my GAC is 12.0. Would that cause a problem?

Answer

Ylli Prifti picture Ylli Prifti · Mar 4, 2016

I had the same Problem (i.e. the same error code Error: 0x1 ...).

The issue was with some of the libraries referenced from a missing folder.

Removing the references and adding them back from the correct path fixed the issue.

The Microsoft Reference (https://msdn.microsoft.com/en-us/library/ms345164.aspx) related to the Error code is very generic and doesn't help you much. However, reading other articles it is quite likely it indicates an unknown failure reason to run the Script Task.

  • Hexadecimal code: 0x1
  • Decimal Code: 1
  • Symbolic Name: DTS_MSG_CATEGORY_SERVICE_CONTROL
  • Description: Incorrect function.