>While I am not sure how to solve it, let me comment on why the error appears. The FOR EACH is executed once for each file, but there is no guarantee that there is any. The TRY part
might have other instructions, outside the FOR EACH loop, that may trigger the CATCH part. In your code, there happen to be no more commands, but the compiler probably doesn't notice that.
>
>One possibility would be to put the TRY/CATCH within the FOR EACH loop, instead of the other way round, but you must decide for yourself whether that fits into your logic.
>
>(BTW, I believe that C# is much stricter with the "definite assignment rule", and the equivalent of your code would not compile at all.)
Thanks, this has resolved the issue.