Compile in memory with VS2005 - Help!!

P

pamelafluente

Hi I am adjusting a project for VS2005. I had this code which worked
fine in VS2003 and now I am having a warning:
Warning 1
'Public Overrides Function CreateCompiler() As
System.CodeDom.Compiler.ICodeCompiler' is obsolete: 'Callers should not
use the ICodeCompiler interface and should instead use the methods
directly on the CodeDomProvider class.

Could you, please, suggest the code changes to adapt this code to
VS2005 (any language will be fine). If appropriate, return result in a
CompilerResults object, as in my code, or equivalent, please.

My VB2003 "OBSOLETE" code:
------------------------------------------------------

Public MyObjectCode As String
Public ICodeCompiler As ICodeCompiler
Public CompilerParameters As CompilerParameters
Public CompilerResults As CompilerResults

Dim VBCodeProvider As New VBCodeProvider
Me.ICodeCompiler = VBCodeProvider.CreateCompiler()
Me.CompilerParameters = New CompilerParameters

With CompilerParameters
.IncludeDebugInformation = False
.GenerateInMemory = True
.GenerateExecutable = False
'... more parameters here
End With

Me.CompilerResults =
Me.ICodeCompiler.CompileAssemblyFromSource(Me.CompilerParameters,
Me.MyObjectCode)

'-------------------------------------------------------------------------------------

Thank you very much in advance!

-Pamela

PS.
As side question, does this warning mean that there is no more need to
instantiate a compiler, because we can use one which is already
instantiated internally?
 
T

tommaso.gastaldi

It's not complicate. This, for instance, would do it (adjust
declarations):

Public MyVBCodeProvider As System.CodeDom.Compiler.CodeDomProvider =
New Microsoft.VisualBasic.VBCodeProvider

Me.CompilerResults =
MyVBCodeProvider.CompileAssemblyFromSource(Me.CompilerParameters,
Me.MyObjectCode)

where Me.MyObjectCode is for instance the code of the class being
compiled and to be later activated, e.g.:

Me.ClassType= CompilerResults.CompiledAssembly.GetType(ClassName)
Me.MyInstance= Activator.CreateInstance(Me.ClassType)

.... etc.

VS2005 is a great improvement. Apart the spectacular IDE, there are a
lot of things greatly improved wherever in the language (using, etc.).
My preferred are those in the area of hashtables (IEqualityComparer,
etc.), that had some problems in the 2003... ;-)

Best programming tool ever, now!

-tom
 

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