jeudi 29 octobre 2015

Tying to create an instance of an object dynamically [duplicate]

This question already has an answer here:

Getting The following Error...

Error 1 Cannot implicitly convert type 'object' to 'CSV_OOP_Convert.FileConverter'. An explicit conversion exists (are you missing a cast?) \server\UserShares\DBell\VSC\CSV_OOP_Convert\CSV_OOP_Convert\Form1.cs 44 39 CSV_OOP_Convert

String className = cmbConversionAlgorithm.Text;
string namespaceName = "CSV_OOP_Convert";

FileConverter myObj =Activator.CreateInstance(Type.GetType(namespaceName + "." + className));
ConvertFile(myObj);

the cmbConversionAlgorithm contains the the correct name of the class i wish to create an instance of.

it works fine whe i create it normally...

CSV_OOP_Convert.TFConverter tfc = new CSV_OOP_Convert.TFConverter();





Aucun commentaire:

Enregistrer un commentaire