I have a Script Task that creates a list of custom objects and sets them to an SSIS object variable.
Custom class:
public class Dog
{
public string Name { get; set; }
}
Code to populate the List and set to an SSIS object variable "myDogs":
public void Main()
{
List<Dog> dogs = new List<Dog>();
Dog dog1 = new Dog();
dog1.Name = "Fido";
Dog dog2 = new Dog();
dog1.Name = "Roofus";
dogs.Add(dog1);
dogs.Add(dog2);
Dts.Variables["myDogs"].Value = dogs;
}
In a second Script Task, I am trying to read my "myDogs" object variable back into a List:
Custom class copied over in the second Script Task:
public class Dog
{
public string Name { get; set; }
}
Main code in my second Script Task:
public void Main()
{
var varDogs = Dts.Variables["myDogs"].Value;
List<Dog> dogs = new List<Dog>();
dogs = (List<Dog>)varDogs;
}
My varDogs object correctly loads the data from my SSIS object variable "myDogs". However, when I try to cast varDogs to a List of type Dog I receive an error message saying "Unable to cast object of type System.Collections.Generic.List".
Does anyone know how I would be able to cast this var data back into a List? Thanks.