I’ve looked on google and other stackoverflow Use of unassigned local variable errors and I still cannot find the answer. I think that maybe my error is cause be misusing the scopes of ExtractionCtrl. I tried this code to test the scope and it works. So I don’t know where is my mistake now.
Testing the scope
namespace RandomTesting
{
internal class Program
{
private static void Main(string[] args)
{
int x = 5;
switch (x)
{
case 2:
System.Console.WriteLine("Your # is 2");
break;
case 5:
System.Console.WriteLine("Your # is :{0}", x);
x = x + 2;
System.Console.WriteLine("Your # is :{0}", x);
break;
}
System.Console.WriteLine("Your # is :{0}", x);
Console.ReadLine();
}
}
}
PART OF THE MAIN CODE
switch (arg)
{
case "AR":
ExtractionCtrl = new ARExtractionController();
// add new mapping here
break;
case "ICN":
ExtractionCtrl = new IcnExtractionController();
// add new mapping here
break;
}
int ticketID;
if (int.TryParse(arg, out ticketID))
{
string returnedFilePath = ExtractionController.GetStartupPath();
ExtractionCtrl.Extract(ticketID, returnedFilePath, AR_TEMPLATE_PATH, MAPPING_PATH);
}
Your switch to set ExtractionCtrl does not have a default-case, so it is possible that ExtractionCtrl is not initalized after the switch. Since you do not show the declaration of ExtractionCtrl, I’m assuming it is declared without initialization:
Hence the error.