Link to home
Start Free TrialLog in
Avatar of Kevin Kearney
Kevin Kearney

asked on

SSIS Package C# error while unzipping files

Hi,

I've got an SSIS package that looks in a folder for zip files and if it finds them it unzips all of them using C# using a reference to system.io.compression.

This is the example I've used:  example

Here is my code:
using Microsoft.SqlServer.Dts.Runtime;
using System.Runtime.InteropServices;
#region Namespaces
using System;
using System.Data;
using System.Windows.Forms;
#endregion
using System.IO.Compression;
using System.IO;
[assembly: ComVisible(false)]
namespace ST_51121ce851f54f58bb7a111e9711bfb7
{
  
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
	{
     
		public void Main()
		{
          
            string zipfullpath = Dts.Variables["User::ZipFullPath"].Value.ToString();
            string inputfolder = Dts.Variables["$Package::InputFolder"].Value.ToString();

            using (ZipArchive arch = ZipFile.OpenRead(zipfullpath))
            { foreach(ZipArchiveEntry entry in arch.Entries)
                {

                    try
                    {
                        entry.ExtractToFile(Path.Combine(inputfolder, entry.FullName));
                    }
                    catch (Exception ex)
                    {
                        //local variable to update error description
                        Variables LockedVariable = null;
                        Dts.VariableDispenser.LockOneForWrite("User::UserErrorDescription", ref LockedVariable);
                        LockedVariable["User::UserErrorDescription"].Value = "Task:ScriptTask,Error Description: " + ex.Message.ToString();
                        LockedVariable.Unlock();
                        //Raise Error event
                        Dts.Events.FireError(0, "Script Task", "Error", string.Empty, 0);
                    }

                }
            }
            File.Delete(zipfullpath);
            
            
                Dts.TaskResult = (int)ScriptResults.Success;
            
         
 
        }

        enum ScriptResults
        {
            Success = DTSExecResult.Success,
            Failure = DTSExecResult.Failure
        };
        #endregion

	}
}

Open in new window



I can't figure out why it fails everytime with error:
   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()

Thanks in advance for advice on this error I really appreciate it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.