title: ssis Error: Exception has been thrown by the target of an invocation
body: <p>The ssis controlflow consists of a script task which trying to open a n excel file and save it as txt file using workbookopen method and saveas methode.
  It shows an error while runing the pkg</p>
  
  <pre><code>The file path is of the format \\11.111.111.1\folder1\folder2\file.xlsx
  
  
   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()
  </code></pre>
  
  <p>The script being used is </p>
  
  <pre><code>Public Sub Main()
  
  
  
          Dim WScript As Object                                    '''= Nothing   '' with out nothing it was showing an error
          Dim oExcel As Object
          Dim oBook As Object
  
  
  
          Dim varoroviderFileLocation_script As String
          Dim varFileName_script As String
          Dim FullPath_script As String
  
          Dim v_Reversestring As String
          Dim v_ReplaceString As String
  
  
  
  
          varoroviderFileLocation_script = Dts.Variables("User::varoroviderFileLocation").Value.ToString()
          varFileName_script = Dts.Variables("User::varFileName").Value.ToString()
          FullPath_script = Dts.Variables("User::varoroviderFileLocation").Value.ToString() + "\" + Dts.Variables("User::varFileName").Value.ToString()
  
          MessageBox.Show(varoroviderFileLocation_script)
          MessageBox.Show(varFileName_script)
          MessageBox.Show(FullPath_script)
  
  
          oExcel = CreateObject("Excel.Application")
  
          oBook = oExcel.Workbooks.Open(FullPath_script)
  
          MessageBox.Show("FullPath_script " + FullPath_script)
  
  
  
  
          v_Reversestring = StrReverse(FullPath_script)
          v_Reversestring = v_Reversestring.Substring(5, Len(v_Reversestring) - 5)
          MessageBox.Show(v_Reversestring)
          v_Reversestring = StrReverse(v_Reversestring)
  
  
  
          v_ReplaceString = v_Reversestring + ".txt"
  
          MessageBox.Show("v_ReplaceString  " + v_ReplaceString)
  
          oBook.SaveAs(v_ReplaceString, -4158)
  
  
  
  
          oBook.Close(False)
          oExcel.Quit()
          WScript.Echo("Done")
  
  
          Dts.TaskResult = ScriptResults.Success
      End Sub
  </code></pre>