472,353 Members | 1,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

An error occurred when programmatically compile another project


The following error occurred when i programmatically compile another project from my present project.

The Error:

error CS0234:The type or namespace name 'Windows' does not exist in the namespace 'System' <are you missing an assembly reference>

The Source Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Globalization;

namespace Compile2

class Class2
/// <summary>
/// The main entry point for the application.
/// </summary>

public bool CompileExecutable(String sourceName)
FileInfo sourceFile = new FileInfo(sourceName);
//CodeDomProvider provider = null;
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
bool compileOk = false;
// provider = new Microsoft.CSharp.CSharpCodeProvider();

if (provider != null)

// Format the executable file name.
// Build the output assembly path using the current directory
// and <source>_cs.exe or <source>_vb.exe.

String exeName = String.Format(@"{0}\{1}.exe",
sourceFile.Name.Replace(".", "_"));

string[] Myref ={ "System.dll","System.Drawing.dll"};//,"System.Windows.Forms.dll","System.Collections.Ge neric.dll","System.ComponentModel.dll","System.Dat a.dll","System.Drawing.dll","System.Text.dll" };
string MyAsm = "MyAsm.dll";

// CompilerParameters cp = new CompilerParameters(Myref, MyAsm);
CompilerParameters cp = new CompilerParameters();

// Generate an executable instead of
// a class library.
cp.GenerateExecutable = true;

// Specify the assembly file name to generate.
cp.OutputAssembly = exeName;

// Save the assembly as a physical file.
cp.GenerateInMemory = false;

// Set whether to treat all warnings as errors.
cp.TreatWarningsAsErrors = false;

// Invoke compilation of the source file.
CompilerResults cr = compiler.CompileAssemblyFromFile(cp, sourceName);

//CompilerResults cr = new CompilerResults();

if (cr.Errors.Count > 0)
// Display compilation errors.
Console.WriteLine("Errors building {0} into {1}",
sourceName, cr.PathToAssembly);
foreach (CompilerError ce in cr.Errors)
Console.WriteLine(" {0}", ce.ToString());
// Display a successful compilation message.
Console.WriteLine("Source {0} built into {1} successfully.",
sourceName, cr.PathToAssembly);

// Return the results of the compilation.
if (cr.Errors.Count > 0)
compileOk = false;
compileOk = true;
return compileOk;


class Program
static void Main(string[] args)
Class2 c2 = new Class2();
c2.CompileExecutable("C:\\temp4\\temp4\\Program.cs ");

Expecting quick Response.
Oct 3 '06 #1
0 1599

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Ayende Rahien | last post by:
reparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error (0xc0000005 at address...
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in...
by: n3crius | last post by:
hi, i just got a web host with asp.net , seemed really cool. aspx with the c# or vb IN the actual main page run fine, but when i use codebehind...
by: JTrigger | last post by:
When I compile my project using the IDE on a development machine it works just fine. When I compile it on the server using csc.exe, I get the...
by: ST | last post by:
Hi, I keep getting the parser error, and I have no idea why. I've tried a number of things including: 1)building/rebuilding about 100x 2)making...
by: Jim Heavey | last post by:
Internal Compiler Error: stage 'BEGIN' Hello, I had an application which was working just fine and I decided to modify all database access within...
by: Jim Heavey | last post by:
Hello, I had an application which was working just fine and I decided to modify all database access within the application to utilizie a new...
by: Ramesh2006 | last post by:
Hi, The following error occurred when i programmatically compile another project from my present project. The Error: error CS0234:The type...
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. ...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.