I have the following code in a script task but when I try execute the script I get an error with the following message: "Exception has been thrown by the target of an invocation. ---> Object reference not set to an instance of an object."
I am trying to address a deadlock error in my package with the use of variables. Based on the value of Region, I'm trying to populate another variable InputRegion.
public void Main()
{
String InputFile;
int StrLen;
Variables var = null;
Dts.VariableDispenser.LockOneForWrite("User::Region", ref var);
var[0].Value = "DEFAULT";
InputFile = (String)vars["User::InputRegion"].Value;
if (InputFile == "Europe.txt")
var[0].Value = "European";
if (InputFile == "Amers.txt")
var[0].Value = "American";
if (InputFile == "Tokyo.txt")
var[0].Value = "Asian";
else
var[0].Value = "Unknown";
var.Unlock();
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
With the given informations, I can guess that :
Variables var = null;
You initialize your variable with a null
valu and then you use it without giving a value.
Because you use it there (probably where you get the exception too)
Dts.VariableDispenser.LockOneForWrite("User::Region", ref var);
If the line of code above doesn't set a value to var, your program could crash :
var[0].Value = "DEFAULT";
var[0].Value = "European";
var[0].Value = "American";
var[0].Value = "Asian";
var[0].Value = "Unknown";
var.Unlock();
Try giving it a valid value instead of null
to make sure the problem is there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.