Dynamic compilation fails

Discussion in 'ASP .Net' started by J.A., Jun 5, 2006.

  1. J.A.

    J.A. Guest

    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());
    }
    }
    J.A., Jun 5, 2006
    #1
    1. Advertising

  2. I was having the same problems as you. I broke out Reflector to see what was
    happening underneath. CompileAssemblyFromSource() doesn't use much of the
    parameters, etc. CompileAssemblyFromFile() however does. So, what worked for
    me was writing my to a temporary file, specify a TempFileCollection(tempPath,
    false) for the parameters and setting the outputAssembly to point to the temp
    area.



    "J.A." wrote:

    > 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());
    > }
    > }
    >
    >
    >
    =?Utf-8?B?bWFyaW8=?=, Aug 18, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Wolfson

    vbc compilation fails when using Hashtable

    Jonathan Wolfson, Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    536
    Tu-Thach
    Jun 27, 2003
  2. Venky
    Replies:
    0
    Views:
    5,390
    Venky
    Feb 6, 2007
  3. Replies:
    11
    Views:
    563
  4. C__chp
    Replies:
    4
    Views:
    493
    Puppet_Sock
    Feb 15, 2008
  5. Lionel
    Replies:
    3
    Views:
    735
    Lionel
    Aug 25, 2008
Loading...

Share This Page