When I build an executable which uses System.Activator.CreateInstance and
execute it on my PC, which has Microsoft Visual Studio installed, the
CreateInstance works just fine and the class constructor is called. But when
I move this executable to another PC (even one with Microsoft Visual Studio)
the execution proceeds all the way to the CreateInstance statement but hangs
there with the constructor never executing.
Any ideas? Is there another way I could do this that might work on the other
PCs.
I do know that once I know the name of the class I can use either an if/else
if construct to have a specific statement for each possible class. I would
rather not do this because I am continually creating new classes and would
have to modify the 'if' each time I added a new class.
A snipit of my code follows:
I set up a global variable:
string DesiredString;
I set up an array of a struct:
struct structProcessClass
{
public string Name;
public Type Class;
}
I fill the array:
structProcessClass tempProcessClass;
Type[] MyTypes = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type thisType in MyTypes)
{
if (thisType.BaseType.ToString() == "ProcessTrackData.ProcessingClass")
{
tempProcessClass.Class = thisType;
tempProcessClass.Name = tempStringOut;
ProcessClasses.Add (tempProcessClass);
}
}
I determine which class I want and instantiate it:
DesiredString = cmbProcessingType.Text;
foreach (structProcessClass thisClass in ProcessClasses)
{
if (thisClass.Name == DesiredString)
{
object[] args = new object[4]{DBFFile, NumberOfRecords, fsr, sw};
DesiredClass =
(ProcessingClass)System.Activator.CreateInstance(t hisClass.Class, args);
break;
}
}