Chris
Chris

Reputation: 53

SSIS ForEach From Variable Enumerator, list created with C# - The object in the variable does not contain an enumerator

I've been chipping away at refactoring an SSIS package that copies a pile of log files into a folder on our network, examines all of the files in the destination folder and then deletes any that have aged past our retention policy. It seems like it should all work but for the error above.

Outline: Variable "dailyFilesToDelete" of type Object, populated by a script task inside a ForEach File Loop. I simplified my code to add a single file that I created to test this new package with and try to get to the heart of the issue.

var fileListDelete = new List<string>();
fileListDelete.Add(@"Q:\xpcttvcpc_live_Full_201912050000.bak");
Dts.Variables["dailyFilesToDelete"].Value = fileListDelete.GetEnumerator();
Dts.TaskResult = (int)ScriptResults.Success;

The next step is the Foreach Loop that is failing.

Enumerator: Foreach From Variable Enumerator

Enumerator variable: User::dailyFilesToDelete

Variable mapping: User::deleteFileName

I suspect that the issue is with how I'm passing my list of strings into dailyFilesToDelete. I initially was passing in the List itself, and once I saw the "variable does not contain an enumerator" error I was sure that adding the GetEnumerator call would fix it.

Upvotes: 1

Views: 2353

Answers (1)

billinkc
billinkc

Reputation: 61211

I believe your issue is assigning the enumerator result to the variable. Try it just as

Dts.Variables["dailyFilesToDelete"].Value = fileListDelete;

Behind the scenes, the SSIS Foreach Enumerator will call the Enumerator method to make the magic happen.

Upvotes: 3

Related Questions