Reputation: 709
I have an SSIS package
that has a script task, that reads from an Excel
.
I am getting the below errors and can't seem to find the issue.
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
I have narrowed the issue down to these 2 lines, where I am setting the Excel
application.
Excel.Application xlApp;
xlApp = new Excel.ApplicationClass();
It's the setting of the value of xlApp
that seems to be causing the error.
I am using Visual Studio 2017.
Can anyone help me out on this?
Upvotes: 1
Views: 1085
Reputation: 37313
Exception has been thrown by the target of an invocation.
Is an general exception that is thrown by Script Task when an error occurred
To read the main error message you can add a try catch clause into your code and use Dts.FireError() method to throw the real exception.
public void Main()
{
try{
Excel.Application xlApp;
xlApp = new Excel.ApplicationClass();
//...rest of code here
Dts.TaskResult = (int)ScriptResult.Success;
}catch(Exception ex){
Dts.FireError(0,"An error occured", ex.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResult.Failure;
}
}
Try using Excel.Application
instead of ApplicationClass
Excel.Application xlApp = new Excel.Application();
Make sure that the Microsoft Excel is installed on the machine and the Interop assemblies are registered in GAC
Upvotes: 1