For testing, I used a console application with the following source code:
public string CODEInString = @"namespace MyNamespace.Generator { public class Calculator { public int Sum(int a, int b) { return a + b; } } }"; public void Create() { var provider = new CSharpCodeProvider(); var cp = new CompilerParameters { GenerateInMemory = false, OutputAssembly = "AutoGen.dll" }; provider.CompileAssemblyFromSource(cp, CODEInString); }
Using this code inside the console application, I can make it work, and the AutoGen.dll file will be created, from this point I can request calculator methods.
My problem occurs when I do the same code, but inside an MVC 3 application. I can catch an exception if I use the following variable.
var compileResult1 = provider.CompileAssemblyFromSource(cp, CODEInString);
'compileResult1.CompiledAssembly' threw an exception of type System.IO.FileNotFoundException '
I also tried using Server.MapPath ("~ / bin /") to tell the output directory.
Can anybody help me? Thanks you
UPDATE 1 I gave permissions to the correct user for recording, so this is not a problem.
source share