CSharpCodeProvider kompilerings fejl, hvorfor?
HejJeg har følgende stump kode:
private object _ExecuteCode()
{
CodeDomProvider codeProvider = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Diagnostics.dll");
List<string> source = new List<string>();
source.Add("using System;");
source.Add("using System.Diagnostics;");
source.Add("class ProcessRunningCheck");
source.Add("{");
source.Add(" public static int ProcessRunning(string processName)");
source.Add(" {");
source.Add(" Process[] processes = Process.GetProcessesByName(processName);");
source.Add(" return processes.Length > 0 ? 1 : 0;");
source.Add(" }");
source.Add("}");
CompilerResults results = codeProvider.CompileAssemblyFromSource(options, source.ToArray());
Type type = results.CompiledAssembly.GetType("ProcessRunningCheck");
MethodInfo method = type.GetMethod("ProcessRunning");
object instance = null;
return method.Invoke(instance, new object[1] { "GoogleUpdate" });
}
Den fejler i linien
Type type = results.CompiledAssembly.GetType("ProcessRunningCheck");
med en exception:
Could not load file or assembly 'file:///C:\Documents and Settings\FRT\Local Settings\Temp\xhcant-b.dll' or one of its dependencies. The system cannot find the file specified.
Jeg ved at det har at gøre med System.Diagnostics assembliet da jeg godt kan gøre det her ved brug af andre assemblies ... man hvorfor er der lige et problem her ?
MVH
Justin Case