Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Embed C# code within VB application

Embed C# code within VB application

Scheduled Pinned Locked Moved C#
csharpdotnetquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jack Knife
    wrote on last edited by
    #1

    I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?

    J H 2 Replies Last reply
    0
    • J Jack Knife

      I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      It's not possible to embed C# within VB.NET source, sadly. You could, however, add any new functionality to a seperate dll. Your VB.NET code can easily call your C# code and vice-versa. FYI, there's lots of programs out there, including some free ones, that automatically convert C# to VB and vice-versa. I suggest doing a google search if you're interested in that. #include "witty_sig.h"

      1 Reply Last reply
      0
      • J Jack Knife

        I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        As Judah said, you could can easily communicate with both because they do compile to IL (this is the fundamental principal of the CLI). A single compiler can't handle both, though. If you want to maintain a single DLL with this, however, there is a way (though VS.NET 2002 and 2003 won't be any help). You can compile either the VB.NET or C# source to a module using the command-line compiler and passing the switch /t:module. When you compile the other language source, you can embed this module into your assembly using /addmodule:_filename_ on the command line, along with the rest of the params (like /t:dll). Your assembly now contains two modules that define the IL. Consumers of your assembly won't know the difference (unless they used a disassembler, but that really doesn't matter).

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups