Doug Reilly's Weblog

Embedded Reporting of the Information Age...

Mixing Languages in .NET Applications

One of the promises of the .NET Framework was that programming language would not matter.  Maybe that is putting it too strongly.  Programming language would of course matter (there are always some things easier in one language than another) but mixing languages should be transparent.  In practice, it seems not to be.

For one thing, if you are using Visual Studio .NET, you are certainly encouraged to use a single language.  For sure, you can have a solution with multiple projects, each in its own language, but how many of us do that?

In practice, I use C# for virtually all my work, unless the client for one reason or another insists upon using VB.NET or J#.  I have a major client, and I had one class that was done for demonstration purposes (using VB.NET, the perferred language of the group I was demonstrating to).  When in a later project for the same client, I had use for that class, it was a bit of a pain having to drop to the command line to compile the VB.NET class into an assembly that could be used by my C# application.

So, if anyone out there does make extensive use of multiple languages in a .NET application, what do you use?  Do you use something like NANT?  The command line?  {shudder}Batch files?

 

Comments

Duncan Mackenzie said:

Why wouldn't you just include that class (the VB.NET one) in a library project, that way you could include it in your solution? Certainly looks cleaner than doing the C# in VS.NET and the VB.NET at the command line.

I've been doing that awhile myself, it isn't unsual for me to have at least one library in another language in a solution... though after awhile, once that library stabilizes I don't really need the actual project open at all... just a reference to the assembly.
# May 17, 2003 3:40 PM

Douglas Reilly said:

Yes, I guess having a library project might be the solution. This was a single class, and so I felt it was overkill, but then again, I griped so about having to drop to the command line, perhaps it would have been worth it<g>.

Not sure how much of a priority it would be for V.Next of VS.NET to allow multi-language projects, but it would go a long way towards encouraging the right tool for the job...
# May 17, 2003 3:47 PM

Addy Santo said:


The project I am working on is primarily in VB.NET, but has several solutions in managed C++ (mostly low level API related stuff which no other languages can reasonably handle), and also some here-and-there C# solutions which are mostly 3rd party solutions which we integrated.

Your assumption regarding a single language is a bit simplistic. Mixing languages in the same solution might be overkill, however in larger development environments it is almost inevitable that the differing characteristics of components will lead to different implementation languages.

-Addy
# May 19, 2003 11:13 AM

John said:

At my company, we have old school VB programmers who insist on programming in VB.NET while, I and some other "younger" developers are C/C++/Java/C# guys.

We've generally agreed that we need to use .NET in future projects, but we're having difficulty getting everyone to agree to use just 1 language especially when you can develop in multiple languages as long as you separate them by containing them in projects.

So the old school guys provide a generic data layer which connects to our AS/400 DB2 server in VB.NET and I programming in ASP.NET using C#. It's working out so far, but I worry if we're going to have trouble maintain the code in the long run. However, reading VB.NET isn't very difficult if you know C# so I don't think it's going to be a big issue.

As for NANT... how can you program without NUnit, NAnt, and CruiseControl.NET? I'm not sure I want to program without Continuous Integration. =) Plus, as others have commented, as long as you include them in a single solution, it's pretty trivial to build all the projects together...
# September 16, 2003 9:47 AM

Bhavin said:

We are trying to use C# project and C++ project (both are managed) in a single .NET solution. However, how do I make C++ procedure calls from C#? I do not know a way of having these interact together.
# March 26, 2004 4:37 PM

Doug Reilly said:

Well, you should have the C++ code export C style functions (that is, declared extern "C"). If you have C++ classes, to call them you will need to create a set of wrappers that exposes the functionality but uses extern "C" functions rather than class members.
# March 26, 2004 4:50 PM

Bhavin said:

Doug,

Are you talking about C# and C++? It seems like you are talking about C and C++. Also, I found something on News Group that talks about __gc for managed C++ classes.

Also, how do I build and link different assembly files? I found an example where different assembly files were built for C++ and VB and then used for C# file but it was all command line. Help please!!!

Thanks,
Bhavin
# March 26, 2004 5:27 PM

Doug Reilly said:

Well, I guess I am talking about all three, C/C++ and C#. YOu will not be abble to call unmanaged C++ code from C# unless you export the methods as extern "C". C++ methods have their names "mangled" or "decorated". One other option would be to have your Managed C++ code call the Unmanaged C++, and then have your C# code call the Managed C++ (something I have not done).
# March 26, 2004 5:32 PM

Alex Pecoraro said:

Regarding mixing languages...

I have a third party VB.NET (ASP.NET) Message Board that I'm trying to figure out how to integrate with my C# (ASP.NET) site.

Any suggestions as to how to tightly integrate two web projects in different languages. I would really like to share session information across them, but my understanding is that since the code is in two seperate projects they won't.

Thanks,
Alex
# April 30, 2004 11:27 AM

Doug Reilly said:

The limitation of a single language per application is a VS.NET restriction, not a restriction imposed by the framework. You could merge required additions to the Web.Config, and deploy all .ASPX and bin\*.dll files, amd I expect it actually would work (I have not done it). Using notepad, it would be easy to do.

Alternately, if the code from one of the sites could be abstracted out to seperate classes, you could integrate the two sites by calling into those classes. This presumes that the .ASPX.CS (or .ASPX.VB) is just a thin layer with event handlers that just call into other classes.
# April 30, 2004 8:30 PM

Alex Pecoraro said:

I've managed to get the code to work by putting the VB.NET codebehind into a seperate assembly. So, my web project has ASPX pages based on both C# and VB.NET

Thanks for the tips.
-Alex
# May 6, 2004 2:17 PM

rickoshay said:

I also use C# exclusively, however, one of my customers is gay, and all there's nothing wrong with that, he obviously prefers Visual Basic. The good news is this is still a homogeneous solution (no pun intended) in that it's 100% Visual Basic.

# December 4, 2008 7:11 PM

nannette said:

Check this out:

pietschsoft.com/.../ASPNET-20-Use-VBNET-and-C-within-the-App_Code-folder.aspx

Step 1: Add the following lines to the web.config

<configuration>

   <system.web>

       <compilation>

           <codeSubDirectories>

               <add directoryName="VB_Code"/>

               <add directoryName="CS_Code"/>

           </codeSubDirectories>

       </compilation>

   </system.web>

</configuration>

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.

For Example:

/App_Code/VB_Code

/App_Code/CS_Code

# November 3, 2010 5:05 PM

duskofanera said:

i have two projects in vb.net & vc++ made in vs 2005

i want to combine these two in single project....

only problem i dont know how to

# April 9, 2011 11:13 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)