saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
603 stars 49 forks source link

Error HRESULT E_FAIL has been returned from a call to a COM component when running inside a SQL Server Integration Services pipeline #79

Open archanavedh opened 3 years ago

archanavedh commented 3 years ago

Hi,

I am getting the below error while trying to execute the below code in script component in SSIS Package on server while it runs good on visual studio if execute manually.

Error: Resize the Image:Error: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100 wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr bufferWirePacket)

Code in Script component: In the below i am trying to resize the image whose length is greater than 400k to less than 400k

region Namespaces

using System; using System.Data; using Microsoft.SqlServer.Dts.Pipeline.Wrapper; using Microsoft.SqlServer.Dts.Runtime.Wrapper; using PhotoSauce.MagicScaler; using System.IO; using System.Text;

endregion

///

/// This is the class to which to add your code. Do not change the name, attributes, or parent /// of this class. /// [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] public class ScriptMain : UserComponent {

region Help: Using Integration Services variables and parameters

/* To use a variable in this script, first ensure that the variable has been added to
 * either the list contained in the ReadOnlyVariables property or the list contained in
 * the ReadWriteVariables property of this script component, according to whether or not your
 * code needs to write into the variable.  To do so, save this script, close this instance of
 * Visual Studio, and update the ReadOnlyVariables and ReadWriteVariables properties in the
 * Script Transformation Editor window.
 * To use a parameter in this script, follow the same steps. Parameters are always read-only.
 *
 * Example of reading from a variable or parameter:
 *  DateTime startTime = Variables.MyStartTime;
 *
 * Example of writing to a variable:
 *  Variables.myStringVariable = "new value";
 */
#endregion

#region Help:  Using Integration Services Connnection Managers
/* Some types of connection managers can be used in this script component.  See the help topic
 * "Working with Connection Managers Programatically" for details.
 *
 * To use a connection manager in this script, first ensure that the connection manager has
 * been added to either the list of connection managers on the Connection Managers page of the
 * script component editor.  To add the connection manager, save this script, close this instance of
 * Visual Studio, and add the Connection Manager to the list.
 *
 * If the component needs to hold a connection open while processing rows, override the
 * AcquireConnections and ReleaseConnections methods.
 * 
 * Example of using an ADO.Net connection manager to acquire a SqlConnection:
 *  object rawConnection = Connections.SalesDB.AcquireConnection(transaction);
 *  SqlConnection salesDBConn = (SqlConnection)rawConnection;
 *
 * Example of using a File connection manager to acquire a file path:
 *  object rawConnection = Connections.Prices_zip.AcquireConnection(transaction);
 *  string filePath = (string)rawConnection;
 *
 * Example of releasing a connection manager:
 *  Connections.SalesDB.ReleaseConnection(rawConnection);
 */
#endregion

#region Help:  Firing Integration Services Events
/* This script component can fire events.
 *
 * Example of firing an error event:
 *  ComponentMetaData.FireError(10, "Process Values", "Bad value", "", 0, out cancel);
 *
 * Example of firing an information event:
 *  ComponentMetaData.FireInformation(10, "Process Values", "Processing has started", "", 0, fireAgain);
 *
 * Example of firing a warning event:
 *  ComponentMetaData.FireWarning(10, "Process Values", "No rows were received", "", 0);
 */
#endregion

/// This method is called once for every row that passes through the component from Input0.
///
/// Example of reading a value from a column in the the row:
///  string zipCode = Row.ZipCode
///
/// Example of writing a value to a column in the row:
///  Row.ZipCode = zipCode
/// </summary>
/// <param name="Row">The row that is currently passing through the component</param>
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    if (!Row.imagecontent_IsNull)
    {
        var settings = new ProcessImageSettings { JpegQuality = 90 };

        var blobData = Row.imagecontent.GetBlobData(0, (int)Row.imagecontent.Length);

        using (MemoryStream msImage = new MemoryStream(blobData))
        {

            //resize image

            for (settings.JpegQuality = 95; settings.JpegQuality >= 5; settings.JpegQuality -= 10)
            {

                MemoryStream msResize = new MemoryStream();

                msImage.Position = 0;
                MagicImageProcessor.ProcessImage(msImage, msResize, settings);

                if (msResize.Length < 400000)
                {
                    msResize.Position = 0;
                    Row.resizeimagecontent.AddBlobData(msResize.ToArray());
                    break;
                }
            }

        }
    }
}

}

saucecontrol commented 3 years ago

Interesting... The call stack stops short of showing any call into MagicScaler, so it's not clear what COM component the error is referring to. It's possible there's some CAS restrictions in place in SSIS that prevent unverifiable code, which would preclude running MagicScaler if so.

archanavedh commented 3 years ago

Interesting... The call stack stops short of showing any call into MagicScaler, so it's not clear what COM component the error is referring to. It's possible there's some CAS restrictions in place in SSIS that prevent unverifiable code, which would preclude running MagicScaler if so.

If I run the package removing this line of code MagicImageProcessor.ProcessImage(msImage, msResize, settings); it gets executed successfully. The issue is with this method MagicImageProcessor.ProcessImage(msImage, msResize, settings);

saucecontrol commented 3 years ago

Right, I have no reason to doubt the call to ProcessImage is failing. However, there is no indication whether the error is inside that method or whether SSIS has failed to load the type or invoke the call in the first place.

Your next troubleshooting step will need to be to get better error information from the SSIS host to determine where the failure is occurring.

archanavedh commented 3 years ago

We are using SQL Server 2012 and Windows Server 2008 R2 and I am not sure how to get better error information from SSIS