CSharpCodeProvider and temporary files

I'm using CSharpCodeProvider.CompileAssemblyFromSource() to compile C# scripts from within a Windows service. Everything works great from my machine but when deployed to our test servers, this error occurs:

Compilation errors: Compilation failed:error CS1619: Cannot create temporary file 'c:\WINNT\system32\CSCDBC.tmp' -- Access is denied.

Is there a way to specify where this temporary file is generated I've tried everything. TempFiles collection doesn't do it. GenerateInMemory doesn't do it.




Answer this question

CSharpCodeProvider and temporary files

  • Andy Burrow

    Actually that doesn't work. I replied in the newsgroups about this. Basically, I used Reflector to view the internals of CSharpCodeProvider. CompileAssemblyFromSource() doesn't use the parameters like you would think. CompileAssemblyFromFile() does so I switched to that. Thanks to Reflector!

    CompileAssemblyFromSource seems to build its temporary file relative to where the current directory is. I guess System32 is the directory for services. I didn't really look more into it. I had a working solution using a restricted account so I'm happy.



  • BJones82

    I don't have the code anymore. I've followed many examples and someone else ran into the same problem. You only have to use Reflector to see it's not using the parameters. I tried all the suggestions from google searches and I could not make CompileAssemblyFromSource work with a Windows services using a severely *restricted* account. I'm not the only one who's been frustrated by this. I'm guessing most who have done on-the-fly scripting use an account with elevated privileges or use a local desktop app.


  • GROTH

    Maybe you configured the compiler by using the CompilerParameters class without setting all parameters or some parameters are conflickting Can you show your source code here

  • Taposh

    TempFiles ultimately does do it. This is of type TempFileCollection. The default constructor of this class will use the temporary directory defined by the environment variables. However there is an overloaded constructor that allows you to specify the directory to store the temporary files in.

    Therefore do the following:

    CSharpCodeProvider prov = new CSharpCodeProvider();
    CompilerParameters parms = new CompilerParameters();
    parms.TempFiles =
    new TempFileCollection(tempdir);

    This will cause temporary files to be put the tempdir directory. However a bigger issue in my opinion is why a service doesn't have access to the temporary directory that it should have access to.

    Michael Taylor - 8/18/06


  • CSharpCodeProvider and temporary files