The objective of the application is to perform statistical analysis on data from a table. The exact makeup of the data/table is determined during run-time by user input, i.e. number and type of columns. I'm able to dynamically create the table but am having trouble filling it with data. The code to fill the table is dynamically created and should only need to be run once. It's basically a bunch of loops generating numbers. I can take the same code that is dynamically generated and create a class in an existing project with it - the code compiles and runs just fine. However, when trying to compile it dynamically I get the following error : The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) I've tried adding 'MySql.Data.MySqlClient.dll', as a CompilerParameter without success. Adding it to the main program as a NuGet Packet doesn't solve the problem either. So how to I add 'MySql.Data' to the parameter list?
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = true;
cp.OutputAssembly = exeName;
cp.GenerateInMemory = false;
cp.TreatWarningsAsErrors = false;
cp.ReferencedAssemblies.Add("System.Data.dll");
cp.ReferencedAssemblies.Add("MySql.Data.MySqlClient.dll"); //doesn't work!
CompilerResults cr = provider.CompileAssemblyFromFile(cp, inSourceName);
Here is the dynamically generated code. It's been stripped down to the bare minimum for testing purposes. If I can get this to compile the rest should work just fine :
string[] programText1 =
{
"using System;",
"using System" + '\u002E' + "Data;",
"using MySql" + '\u002E' + "Data" + '\u002E' + "MySqlClient;",
"namespace Mouse",
"{",
"\tstatic class Program",
"\t{",
"\t\tstatic string masterConnString = \"Server = localhost; User Id = root; Persist Security Info = True; database = testing_database; Password = sql832SQL *#@;\";",
"\t\tstatic MySqlConnection masterConnection = new MySqlConnection(masterConnString);",
"",
"\t\tstatic void Main()",
"\t\t{",
"\t\t\tConsole.WriteLine(\"Hello Cruel World!\");",
"\t\t\tConsole.ReadLine();",
"\t\t}"
};