J
J.A.
Hi,
I'm trying to use the CSharpCompilerProvider to dynamically compile some
code. The test console app works fine but I get this error when using the
same code in an ASP.NET app:
error CS1619: Cannot create temporary file
'c:\WINDOWS\system32\CSCCB.tmp' -- Access is denied.
I attached the code I use to compile the dynamic code at the bottom. I tried
with and without specifying the TempFileCollection, I also tried to compile
from source and from file.
It seems there isn't much information available so I figured I would ask
here.
Any suggestions ?
J.
--
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
string fn = Path.GetTempFileName();
using(StreamWriter sw = File.CreateText(fn))
{
sw.WriteLine(
@"namespace Foo
{
public class Bar
{
public int Test() { return 1; }
}
}");
}
parameters.OutputAssembly = "testAssembly";
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = false;
parameters.IncludeDebugInformation = false;
parameters.ReferencedAssemblies.Add("System.dll");
parameters.TempFiles = new TempFileCollection(Path.GetTempPath());
CompilerResults cr = provider.CompileAssemblyFromFile(parameters, fn);
if(cr.Errors.Count > 0)
{
// Display compilation errors.
System.Diagnostics.Debug.WriteLine("Errors during compilation");
foreach(CompilerError ce in cr.Errors)
{
System.Diagnostics.Debug.WriteLine(ce.ToString());
}
}
I'm trying to use the CSharpCompilerProvider to dynamically compile some
code. The test console app works fine but I get this error when using the
same code in an ASP.NET app:
error CS1619: Cannot create temporary file
'c:\WINDOWS\system32\CSCCB.tmp' -- Access is denied.
I attached the code I use to compile the dynamic code at the bottom. I tried
with and without specifying the TempFileCollection, I also tried to compile
from source and from file.
It seems there isn't much information available so I figured I would ask
here.
Any suggestions ?
J.
--
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
string fn = Path.GetTempFileName();
using(StreamWriter sw = File.CreateText(fn))
{
sw.WriteLine(
@"namespace Foo
{
public class Bar
{
public int Test() { return 1; }
}
}");
}
parameters.OutputAssembly = "testAssembly";
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = false;
parameters.IncludeDebugInformation = false;
parameters.ReferencedAssemblies.Add("System.dll");
parameters.TempFiles = new TempFileCollection(Path.GetTempPath());
CompilerResults cr = provider.CompileAssemblyFromFile(parameters, fn);
if(cr.Errors.Count > 0)
{
// Display compilation errors.
System.Diagnostics.Debug.WriteLine("Errors during compilation");
foreach(CompilerError ce in cr.Errors)
{
System.Diagnostics.Debug.WriteLine(ce.ToString());
}
}