My variable is a string at the package level and have added it as readwritevariable example:
public void Main()
{
string sServer = "localhost";
Dts.Variables["User::sourceServer"].Value = sServer;
}
will result in Error: The type of the value being assigned to variable differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.