Programmatically Compiling CSharp Code Using C# Compiler ???

A

Alex

Hi,

The following article describes how to compile CSharp code
programmatically http://support.microsoft.com/default.aspx?
scid=http://support.microsoft.com:80/support/kb/articles/Q3
04/6/55.asp&NoWebContent=1

When I'm trying to compile CSsharp code (See code below)
which includes the "using System.Data" namespace I'm
receiving the following error message

Line number 3, Error Number: CS0234, 'The type or
namespace name 'Data' does not exist in the class or
namespace 'System' (are you missing an assembly
reference?);

Can anyone tell what is wrong?


using System;
using System.Data;

namespace HelloWorld
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class HelloWorldClass
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

Thanks,
Alexander
 
N

Nicholas Paldino [.NET/C# MVP]

Alex,

When you are compiling, are you referencing System.Data.dll? You need
to set the reference so the compiler knows about the types in that assembly.
The "using" directive is just shorthand so you dont always have to use the
full type name, it doesn't pull in the reference.

Hope this helps.
 
G

Guest

Is it possible to set up the reference programmatically?
What lines of code should I add to my SCharp code sample?

Thanks,
Alex
-----Original Message-----
Alex,

When you are compiling, are you referencing System.Data.dll? You need
to set the reference so the compiler knows about the types in that assembly.
The "using" directive is just shorthand so you dont always have to use the
full type name, it doesn't pull in the reference.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alex said:
Hi,

The following article describes how to compile CSharp code
programmatically http://support.microsoft.com/default.aspx?
scid=http://support.microsoft.com:80/support/kb/articles/Q3
04/6/55.asp&NoWebContent=1

When I'm trying to compile CSsharp code (See code below)
which includes the "using System.Data" namespace I'm
receiving the following error message

Line number 3, Error Number: CS0234, 'The type or
namespace name 'Data' does not exist in the class or
namespace 'System' (are you missing an assembly
reference?);

Can anyone tell what is wrong?


using System;
using System.Data;

namespace HelloWorld
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class HelloWorldClass
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

Thanks,
Alexander


.
 
N

Nicholas Paldino [.NET/C# MVP]

When calling the static Compile method, the imports parameter should be
populated with an array of strings representing the assemblies to import for
the build.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is it possible to set up the reference programmatically?
What lines of code should I add to my SCharp code sample?

Thanks,
Alex
-----Original Message-----
Alex,

When you are compiling, are you referencing System.Data.dll? You need
to set the reference so the compiler knows about the types in that assembly.
The "using" directive is just shorthand so you dont always have to use the
full type name, it doesn't pull in the reference.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alex said:
Hi,

The following article describes how to compile CSharp code
programmatically http://support.microsoft.com/default.aspx?
scid=http://support.microsoft.com:80/support/kb/articles/Q3
04/6/55.asp&NoWebContent=1

When I'm trying to compile CSsharp code (See code below)
which includes the "using System.Data" namespace I'm
receiving the following error message

Line number 3, Error Number: CS0234, 'The type or
namespace name 'Data' does not exist in the class or
namespace 'System' (are you missing an assembly
reference?);

Can anyone tell what is wrong?


using System;
using System.Data;

namespace HelloWorld
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class HelloWorldClass
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

Thanks,
Alexander


.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top