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.

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
GROTH
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