admin管理员组

文章数量:1289349

We are using the following source code for a Script Task of SSIS, targeting .NET Framework v4.7, and the corresponding C# language version should be v7.3.

The source code can build successfully, however, when running in Visual Studio, RegionEndpoint regionEndpoint = RegionEndpoint.USEast1; always triggers the following exception:

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()

For testing, if we comment out RegionEndpoint regionEndpoint = RegionEndpoint.USEast1;, the script task can run successfully. So, we confirmed the culprit is in this line.

We highly appreciate any hints and suggestions.

Details

  1. Partial project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns=";>
  <PropertyGroup>
...
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
...
  </PropertyGroup>
...
  <ItemGroup>
    <Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
      <HintPath>C:\my\work\xxx\packages\AWSSDK.Core.3.7.402.3\lib\net45\AWSSDK.Core.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>C:\Users\user.name\AppData\Local\Temp\Vsta\SSIS_ST160\xxx\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.SqlServer.ManagedDTS, Version=16.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    <Reference Include="Microsoft.SqlServer.ScriptTask, Version=16.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  </ItemGroup>
...
</Project>
  1. The source code of C# Script Task in SSIS:
#region Namespaces
using System;
using Amazon;
#endregion

namespace ST_xxx
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public async System.Threading.Tasks.Task Main()
        {
            try
            {
                string regionName = "us-east-1";
                RegionEndpoint regionEndpoint = RegionEndpoint.USEast1;
            }
            catch (Exception ex)
            {
                Dts.Events.FireError(0, "Error", ex.Message, string. Empty, 0);
                throw;
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }

        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    }
}

We are using the following source code for a Script Task of SSIS, targeting .NET Framework v4.7, and the corresponding C# language version should be v7.3.

The source code can build successfully, however, when running in Visual Studio, RegionEndpoint regionEndpoint = RegionEndpoint.USEast1; always triggers the following exception:

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()

For testing, if we comment out RegionEndpoint regionEndpoint = RegionEndpoint.USEast1;, the script task can run successfully. So, we confirmed the culprit is in this line.

We highly appreciate any hints and suggestions.

Details

  1. Partial project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft/developer/msbuild/2003">
  <PropertyGroup>
...
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
...
  </PropertyGroup>
...
  <ItemGroup>
    <Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
      <HintPath>C:\my\work\xxx\packages\AWSSDK.Core.3.7.402.3\lib\net45\AWSSDK.Core.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>C:\Users\user.name\AppData\Local\Temp\Vsta\SSIS_ST160\xxx\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.SqlServer.ManagedDTS, Version=16.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    <Reference Include="Microsoft.SqlServer.ScriptTask, Version=16.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  </ItemGroup>
...
</Project>
  1. The source code of C# Script Task in SSIS:
#region Namespaces
using System;
using Amazon;
#endregion

namespace ST_xxx
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public async System.Threading.Tasks.Task Main()
        {
            try
            {
                string regionName = "us-east-1";
                RegionEndpoint regionEndpoint = RegionEndpoint.USEast1;
            }
            catch (Exception ex)
            {
                Dts.Events.FireError(0, "Error", ex.Message, string. Empty, 0);
                throw;
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }

        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    }
}
Share Improve this question edited Feb 20 at 15:48 Mike asked Feb 20 at 1:03 MikeMike 851 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

We have resolved this issue by manually adding the AWSSDK.Core.dll to the GAC (global assembly cache).

SSIS Script Task standard is a little behind the latest .NET Framework, so the current latest standard is .NET Framework v4.7. And the project targets to SQL Server 2016. With this specification, we need to:

  • Go to Visual Studio project directory project\packages\AWSSDK.Core.3.7.402.3\lib\net45\, and copy AWSSDK.Core.dll into C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\.
  • Run "Visual Studio Developer Command Prompt" as administrator, and call command gacutil -i "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\AWSSDK.Core.dll".
  • In Visual Studio, open source code editor of the SSIS package's Script Task, and manually add a reference to the DLL file above.
  • For deployment on the SQL Server, we need to copy the DLL and call the gacutil command as well.

For some reason, the exception message did not return useful information to indicate missing DLL. This is still a question for us.

本文标签: