Using CodeDOM in .NET 2.0
page 5 of 8
by Uday Denduluri
Feedback
Average Rating: 
Views (Total / Last 10 Days): 41641/ 107

CodeDOM in .NET Framework 2.0

Programmers who are used to developing applications in CodeDOM (.NET Framework 1.x) will encounter a warning in .NET Framework 2.0: “System.CodeDom.Compiler.CodeDomProvider.CreateCompiler() is obsolete: Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class.”   Problems may be with the code given below.

The Code snippet below explains the issue of .NET 1.x code having problems in .NET 2.0.  It explains the enriched functionality of the CodeDomProvider class.  The code uses namespaces like “System.CodeDom,” “System.CodeDom.Compiler” and “Microsoft.CSharp.”  The code below assumes that the reader understands the syntax of C# language and is well versed with the basic programming techniques.

Listing 4

ICodeCompiler iCodeCompiler = new CSharpCodeProvider().CreateCompiler();
iCodeCompiler.CompileAssemblyFromSource(compilerParameters, strcode);

In .NET Framework 2.0, CodeDomProvider itself encapsulates all of the iCodeCompiler methods. Therefore, we better use a reference of the CodeDOM provider and use it as shown below.

CodeDomProvider  codeDomProvider = new CSharpCodeProvider();
CompilerResults compilerResults =
 codeDomProvider.CompileAssemblyFromSource(compilerParameters, code);

The ICodeCompiler is an obsolete method and a programmer should try to avoid it.


View Entire Article

User Comments

Title: 123   
Name: 123
Date: 2012-12-13 7:37:12 AM
Comment:
13
Title: Pointless article   
Name: Poin Tless
Date: 2009-08-17 12:17:46 AM
Comment:
Your article is a pointless copy and paste for nothing more than putting something on the web with your name on it. Learn to program you loser
Title: Query   
Name: Reetesh
Date: 2008-08-01 8:52:06 PM
Comment:
Hi,

I have read this Article. and I have seen the code but can u tell me where I write the code and how to use it. Please send me a sample code for it.

thanks
Title: Query   
Name: Reetesh
Date: 2007-06-05 6:16:56 AM
Comment:
Hi,

I have read this Article. and I have seen the code but can u tell me where I write the code and how to use it. Please send me a sample code for it.

thanks






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-03-08 7:02:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search