Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamic compilation fails

Reply
Thread Tools

Dynamic compilation fails

 
 
J.A.
Guest
Posts: n/a
 
      06-05-2006
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());
}
}


 
Reply With Quote
 
 
 
 
=?Utf-8?B?bWFyaW8=?=
Guest
Posts: n/a
 
      08-18-2006
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());
> }
> }
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic compilation fails with "cannot be resolved to a type" Lionel Java 3 08-25-2008 11:29 AM
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
Function declared before call but defined after - compilation fails johnbrown105@hotmail.com C++ 11 05-18-2007 05:13 PM
WSDL compilation fails with faultcode as INVALID_WSDL Venky Java 0 02-06-2007 11:11 AM
vbc compilation fails when using Hashtable Jonathan Wolfson ASP .Net 1 06-27-2003 04:40 PM



Advertisments