Personal License


  • Perpetual license (does not expire)
  • 1 site, unlimited servers
  • No distribution (hosted use only)
  • Commercial use allowed
$29.99 Read License

Developer License


  • Perpetual license (does not expire)
  • Unlimited projects
  • Can distribute code and binary products
  • Commercial use allowed
$59.99 Read License

14 Day money-back guarantee

Full refund within 14 days of purchase date.

You need to log-in or create an account
  • Create an account
  • Log-in

Please use your real name.

Activation link will be sent to this address.

Minimum 8 characters

Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

  • Released: Feb 3, 2011
    Last Update: Feb 2, 2011
  • Language: VB.NET
    Framework: ASP.NET

Compile .Net code on the fly - VB.Net

Compile .Net code on the fly - VB.Net
Developed by Jamie Plenderleith, Released Feb 3, 2011

Compile and execute .NET code on the fly

VB.NET

Tags: .net , compiler , contest2011 , execute

The CustomCompiler class in this component will compile and execute any .NET code passed to it as a string.
Simply add the CustomCompiler class to any existing project for compile-on-the-fly functionality!

Back to top

Installation and usage

To install the CustomCompiler class drop the CustomCompiler.vb class into an existing project.

It's very easy to use the CustomCompiler class. There are a number of code samples enclosed in the component's zip file. Simply create a new instance of the CustomCompiler class, and call its ExecuteCode() method.

For example:

'Create a new instance of the custom compiler class
        Dim myCustomCompiler As New CustomCompiler()

        'An example of a full class to be compiled and executed
        Dim AppCode1 = 
                            Imports System
                            Class MyTestClass
                                Public Sub MyMethod()
                                    Console.WriteLine("This line of VB.Net was executed dynamically.")
                                End Sub
                            End Class

        myCustomCompiler.ExecuteCode(AppCode1, "MyTestClass.MyMethod", CustomCompiler.CodeScope.FullClassProvided, "VisualBasic")

        'An example of a full class to be compiled and executed in C#
        Dim AppCode2 = 
                            using System;
                            class someTestClass {
                                public void myMethod() {
                                    Console.WriteLine("This line of C# was executed dynamically.");
                                }
                            }

        myCustomCompiler.ExecuteCode(AppCode2, "someTestClass.myMethod", CustomCompiler.CodeScope.FullClassProvided, "C#")

        'An example of a snippet of code to be compiled and executed
        Dim SnippetCode1 = 
                              Dim x As Integer = 5
                              Dim y As Integer = 6
                              Dim z As Integer = x + y 
                              Console.WriteLine("{0} + {1} = {2}", x, y, z)

        myCustomCompiler.ExecuteCode(SnippetCode1, Nothing, CustomCompiler.CodeScope.SnippetOnlyStatements, "VisualBasic")

        'Another example of a snippet of code to be compiled and executed
        Dim SnippetCode2 = 
                              Const val1 = 9
                              Dim val2 As Integer = System.Math.Sqrt(val1)
                              My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\testfile.txt", val2, True)
                              Console.WriteLine("Value has been written to text file")

        myCustomCompiler.ExecuteCode(SnippetCode2, Nothing, CustomCompiler.CodeScope.SnippetOnlyStatements, "VisualBasic")

        'An example of a snippet of code that includes methods, to be compiled and executed
        Dim BiggerSnippetCode = 
                                    private int GetMyValue() {
                                        int x = 5;
                                        int y = 6;
                                        int z = x + y;
                                        return z;
                                    }
                                    public void ExecuteMe() {
                                        Console.WriteLine("Some value = {0}", GetMyValue());
                                    }

        myCustomCompiler.ExecuteCode(BiggerSnippetCode, "ExecuteMe", CustomCompiler.CodeScope.SnippetWithMethods, "C#")

User Reviews

No reviews have been submitted yet.
Read all 1 comments »

Questions & Comments


Or enter your name and Email
  • Mary 2 years ago
    I want to compile code that a user enters into a textbox. The code will contain functions that I provide the user with. Will I be able to use the custom compiler class to compile the code in vb?
You must be logged-in to vote. Log-in to your account or register now.