473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VBCodeProvider

When I compile the following code, it works fine only one time. At the
second time the following error occurs.

Can somebody help me?

vbc : Command line (0,0) : error BC2006: option 'r' requires ':<file_list>'

=================================
Public Function Eval(ByVal vbCode As String) As Object

Dim oCodeProvider As VBCodeProvider = New VBCodeProvider

' Obsolete in 2.0 framework

' Dim oICCompiler As ICodeCompiler = oCodeProvider.CreateCompiler

Dim oCParams As CompilerParameters = New CompilerParameters

Dim oCResults As CompilerResults

Dim oAssy As System.Reflection.Assembly

Dim oExecInstance As Object = Nothing

Dim oRetObj As Object = Nothing

Dim oMethodInfo As MethodInfo

Dim oType As Type

Try

' Setup the Compiler Parameters

' Add any referenced assemblies

Dim asm As [Assembly]

For Each asm In AppDomain.CurrentDomain.GetAssemblies()

oCParams.ReferencedAssemblies.Add(asm.Location)

Next

oCParams.CompilerOptions = "/t:library"

oCParams.GenerateInMemory = True

' Generate the Code Framework

Dim sb As StringBuilder = New StringBuilder("")

sb.Append("Imports System" & vbCrLf)

sb.Append("Imports System.Xml" & vbCrLf)

sb.Append("Imports System.Data" & vbCrLf)

' Build a little wrapper code, with our passed in code in the middle

sb.Append("Namespace dValuate" & vbCrLf)

sb.Append("Class EvalRunTime " & vbCrLf)

sb.Append("Public Function EvaluateIt() As Object " & vbCrLf)

sb.Append(vbCode & vbCrLf)

sb.Append("End Function " & vbCrLf)

sb.Append("End Class " & vbCrLf)

sb.Append("End Namespace" & vbCrLf)

Debug.WriteLine(sb.ToString())

Try

' Compile and get results

' 2.0 Framework - Method called from Code Provider

oCResults = oCodeProvider.CompileAssemblyFromSource(oCParams, sb.ToString)

' 1.1 Framework - Method called from CodeCompiler Interface

' cr = oICCompiler.CompileAssemblyFromSource (cp, sb.ToString)

' Check for compile time errors

If oCResults.Errors.Count <0 Then

Me.CompilerErrors = oCResults.Errors

Throw New Exception("Compile Errors")

Else

' No Errors On Compile, so continue to process...

oAssy = oCResults.CompiledAssembly

oExecInstance = oAssy.CreateInstance("dValuate.EvalRunTime")

oType = oExecInstance.GetType

oMethodInfo = oType.GetMethod("EvaluateIt")

oRetObj = oMethodInfo.Invoke(oExecInstance, Nothing)

Return oRetObj

End If

Catch ex As Exception

' Compile Time Errors Are Caught Here

' Some other weird error

Debug.WriteLine(ex.Message)

Stop

End Try

Catch ex As Exception

Debug.WriteLine(ex.Message)

Stop

End Try

Return oRetObj

End Function
Jun 27 '08 #1
0 1359

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marco Viana | last post by:
Hi, I'm developing an ASP.NET application with Visual Studio .NET 2003 in a Win XP Professional, .NET Framework 1.1 and IIS 5.1 computer with all the lattest patches. When testing a page...
3
by: jack | last post by:
Trying to make a utility that - Reads a VB.Net source file - Parses it into it's constuent parts - Evaluates and modifies as required - Saves the source I thought that the CodeDom and the...
18
by: Franky | last post by:
I don't know how to ask this so that someone will not misread it but here goes. At run time I want to be able to evaluate functions from the Math library, but at design time I do not know what...
2
by: Franky | last post by:
using Dim VBCodeProvider As New VBCodeProvider the first time my code is run, to compile and run the sample code it works OK the second time my code is run, to compile and run the same...
2
by: Frank | last post by:
I'm using to compile at runtime with VBCodeProvider Now I'm wondering if it will work on a machine without VS or some other compiler on it. I mean, is this like using Word for spell check,...
40
by: PJ6 | last post by:
I want to rant, but I'm too busy at the moment. Who else hates working in C#? What's your biggest pet peeve? Paul
0
by: =?Utf-8?B?WmlnZ3lTaG9ydA==?= | last post by:
If using VBCodeProvider/CSharpCodeProvider to get an ICodeCompiler I get a CompileAssemblyFromFile compilation error when referencing or instantiating classes which exist in the host application. ...
0
by: Alexander Vasilevsky | last post by:
How to configure VBCodeProvider that can be used Linq- improve language? http://www.alvas.net - Audio tools for C# and VB.Net developers
0
by: Gabriel Ferrarini | last post by:
When I compile the following code, it works fine only one time. At the second time the following error occurs. Can somebody help me? vbc : Command line (0,0) : error BC2006: option 'r'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.