How can I run the compiled code in the current AppDomain in NET Framework 4.0? Below the code that works in net framework 3.5, but objCompilerParameters.Evidence is obsolete in NET Framework 4.0 so how to solve it?
protected void Button1_Click(object sender, EventArgs e)
{
VBCodeProvider objVBCodeProvider = new VBCodeProvider();
CompilerParameters objCompilerParameters = new CompilerParameters();
objCompilerParameters.ReferencedAssemblies.Add("System.dll");
objCompilerParameters.Evidence = AppDomain.CurrentDomain.Evidence;
objCompilerParameters.CompilerOptions = string.Empty;
objCompilerParameters.GenerateExecutable = false;
objCompilerParameters.GenerateInMemory = false;
objCompilerParameters.IncludeDebugInformation = false;
objCompilerParameters.TreatWarningsAsErrors = false;
objCompilerParameters.WarningLevel = 0;
objCompilerParameters.ReferencedAssemblies.Add(this.GetType().Assembly.Location);
// source contains the code, is of type string
CompilerResults cr = objVBCodeProvider.CompileAssemblyFromSource(objCompilerParameters,source);
if (cr.Errors.HasErrors)
{ Console.WriteLine("Error");
foreach (CompilerError err in cr.Errors)
{ Console.WriteLine(err.ErrorText); } }
else
{
// Some things...
}
}