In writing an SSIS package (BIDS version 2012), I have declared a package level variable strFileLocation and set it to type String and gave it a value of "C:\Temp\file.txt".
In the SSIS package I then created a C# script task. Opening the script task editor, I declared the strFileLocation variable to be a ReadOnlyVariable.
Then I opened the script editor and declared this C# variable
string strFilePath = ""
And then I wrote this line of code:
strFilePath = Dts.Variables["strFileLocation"].Value;
But this code does not work, generating this compilation error:
cannot implicitily convert type 'object' to 'string'. An explicit conversion exists(are you missing a cast?)
I was able to fix the problem by using this code:
strFilePath = Dts.Variables["strFileLocation"].Value.ToString();
It would seem that the SSIS type string is not the same as the C# type string. Does this have something to do with Unicode? And will I always have to explicity convert my SSIS variables to an appropriate C# datatype counterpart?