Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:03:14+00:00 2026-05-23T06:03:14+00:00

I need to create a VB.NET function that takes the source code of a

  • 0

I need to create a VB.NET function that takes the source code of a VB.NET console application and compile it into a console application.

For example, this is the VB.NET source code for the console application:

Module Module1

    Sub Main()
        Dim UserInfo As String = "Name: User1"

        System.Console.WriteLine(UserInfo)
        System.Console.ReadLine()
    End Sub

End Module

My code so far:

Friend Function CreateConsoleApplication(ByVal VBSourceCode As String, ByVal WhereToSave As String) As Boolean
    Try
        'now compile the source code contained in 
        'VBSourceCode string variable

    Catch ex As Exception
        MessageBox.Show(ex.ToString)
        Return False
    End Try
End Function

UPDATE: Here is the solution:-

  Friend Function CreateConsoleApplication(ByVal VBSourceCode As String, ByVal WhereToSave As String) As Boolean
        Try

            VBSourceCode = "Module Module1" & vbCrLf & "Sub Main()" & vbCrLf & "Dim UserInfo As String = ""Name: User1""" & vbCrLf & "System.Console.WriteLine(UserInfo)" & vbCrLf & "System.Console.ReadLine()" & vbCrLf & "End Sub" & vbCrLf & "End Module"
            WhereToSave = "E:\TestConsole.exe"

            Dim provider As Microsoft.VisualBasic.VBCodeProvider
            Dim compiler As System.CodeDom.Compiler.ICodeCompiler
            Dim params As System.CodeDom.Compiler.CompilerParameters
            Dim results As System.CodeDom.Compiler.CompilerResults

            params = New System.CodeDom.Compiler.CompilerParameters
            params.GenerateInMemory = False

            params.TreatWarningsAsErrors = False
            params.WarningLevel = 4
            'Put any references you need here - even you own dll's, if you want to use one

            Dim refs() As String = {"System.dll", "Microsoft.VisualBasic.dll"}
            params.ReferencedAssemblies.AddRange(refs)
            params.GenerateExecutable = True
            params.OutputAssembly = WhereToSave

            provider = New Microsoft.VisualBasic.VBCodeProvider
            results = provider.CompileAssemblyFromSource(params, VBSourceCode)

            Return True
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            Return False
        End Try
    End Function

Ok, now the code can compile VB.NET source code into VB.NET console application, thanks ! But how do we check if there is any error in this results variable, I mean this line: results = provider.CompileAssemblyFromSource(params, VBSourceCode)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:03:14+00:00Added an answer on May 23, 2026 at 6:03 am

    The “Obsolete” warning message tells you how to avoid receiving it – use the method defined on the CodeProvider class directly, e.g.

    provider = New Microsoft.VisualBasic.VBCodeProvider
    'compiler = provider.CreateCompiler
    results = provider.CompileAssemblyFromSource(params, VBSourceCode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a service in .NET that maintains (inner) state in-memory, spawns
I need to create a web application using ASP.NET MVC, jQuery and web standards
I would like to create a function in C# that takes a specific webpage
I need to create a function that is only necessary inside one cshtml file.
I need to call a function that takes an array of drive letters as
For a project I am doing I need to manually create a .net project.
I need to create reports in a C# .NET Windows app. I've got an
We need to create an .xls file in ASP .NET which will be imported
I need to create a custom membership user and provider for an ASP.NET mvc
Why do we need to create custom exceptions in .NET?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.