SSIS Script Task throwing exception: The type initializer for 'PerTypeValues'1'

James Clark 231 Reputation points
2021-06-07T16:04:57.323+00:00

I have a C# Script Task that's throwing an exception "The type initializer for 'PerTypeValues'1" running on the server. My package runs fine within Visual Studio. What the heck does this mean?

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
{count} votes

Accepted answer
  1. CarrinWu-MSFT 6,891 Reputation points
    2021-06-09T01:40:43.89+00:00

    Hi @James Clark , sorry about that I don't familiar with C#. But after researched, this error may occurred when the script have something wrong. Please refer to this thread:

    Check the InnerException property of the TypeInitializationException; it is likely to contain information about the underlying problem, and exactly where it occurred.

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. CarrinWu-MSFT 6,891 Reputation points
    2021-06-08T06:45:52.497+00:00

    Hi @James Clark ,

    Welcome to Microsoft Q&A!

    I found a similar issue with yours, the poster said the issue has been fixed by instanll PowerShell Tools for Visual Studio 2017. So please check that have you install CS-Script Tools for Visual Studio. In addition, please chose right version for your Visual Studio.

    Best regards,
    Carrin


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. James Clark 231 Reputation points
    2021-06-07T20:18:39.357+00:00

    Yes, I'm using assemblies pertaining to the use of System.Text.Json:

    • System.Text.Json version 4.0.1.0
    • System.Buffers.dll version 4.0.2.0
    • System.Memory.dll version 4.0.1.1

    Refer to https://learn.microsoft.com/en-us/answers/questions/414330/how-to-set-up-the-use-of-systemtextjson-within-a-s.html

    Here's the script code:

    public void Main()  
    {  
            // TODO: Add your code here  
            const string curlResponseCode = "CurlResponseCode";  
            const string taskOutputArrayName = "PackageIdArray";  
      
            try  
            {  
                var stream = new FileStream(Dts.Connections["TeamworkCloudModelElementJsonOne"].ConnectionString, FileMode.Open);  
      
                JsonDocument document = JsonDocument.Parse(stream);  
                stream.Close();  
      
                ArrayList packageIdArray = new ArrayList();  
                foreach (JsonElement kermlOwnedElement in document.RootElement[1].GetProperty("kerml:ownedElement").EnumerateArray())  
                {  
                    packageIdArray.Add(kermlOwnedElement.GetProperty("@id").GetString());  
                }  
                if (Dts.Variables.Contains(taskOutputArrayName))  
                    Dts.Variables[taskOutputArrayName].Value = packageIdArray;  
                else  
                    throw new ApplicationException("Missing variable to set: " + taskOutputArrayName);  
      
                document.Dispose();  
                Dts.TaskResult = (int)ScriptResults.Success;  
            }  
            catch (Exception ex)  
            {  
                Dts.Events.FireError(ex.HResult, string.Empty, "Exception thrown: " + ex.Message, string.Empty, 0);  
      
                Dts.TaskResult = (int)ScriptResults.Failure;  
            }  
            finally  
            {  
                bool fireAgain = false;  
      
                if (Dts.Variables.Contains(curlResponseCode))  
                    Dts.Events.FireInformation(0, string.Empty, "Curl Response Code: " + Dts.Variables[curlResponseCode].Value, string.Empty, 0, ref fireAgain);  
            }  
    }  
    
    0 comments No comments

  3. Yitzhak Khabinsky 26,586 Reputation points
    2021-06-07T21:32:24.75+00:00

    Hi @James Clark ,

    First make sure that the SSIS run-time server has the same .Net Framework version as refered by the SSIS Script Task.

    Please check this link: installing System.Memory 4.5.2 explicitly solves the issue


  4. James Clark 231 Reputation points
    2021-06-07T21:48:24.76+00:00

    I've confirmed that both the server and the Script Task are using .NET Framework v4.7.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.