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:
I can't figure out why it fails everytime with error:
at System.RuntimeMethodHandle .InvokeMet hod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeM ethodInfo. UnsafeInvo keInternal (Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeM ethodInfo. Invoke(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeM ember(Stri ng name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Ta sks.Script Task.VSTAT askScripti ngEngine.E xecuteScri pt()
Thanks in advance for advice on this error I really appreciate it.
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
}
}
I can't figure out why it fails everytime with error:
at System.RuntimeMethodHandle
at System.Reflection.RuntimeM
at System.Reflection.RuntimeM
at System.RuntimeType.InvokeM
at Microsoft.SqlServer.Dts.Ta
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 TRIALMembers 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.