tags:

views:

320

answers:

6

Hello all

I have a vb.net solution and I want to add there a new dll files written in c# and use the functionality from the dll, in the code written in vb.net.

I made several uses of it and it seems working all right, but is it a smart thing to do messing vb.net code with c# like I want to do .

And what a dangers of what I am doing ?

Thank a lot for help .

+3  A: 

You can mix VB and C# code in the same project - I have worked on several projects that have mixed them and have no issues.

You language mix seems to be much more isolated - one solution with multiple C# DLLs and vb project(s).

I don't see many issues with that.

Raj More
Surely you meant "same solution"? Mixing in one project can't work.
Hans Passant
It can work in an ASP.NET "Web Site" project.
Kyralessa
It is possible to have two languages in the same project - just not in the same file.
Raj More
+10  A: 

Your DLL is not a C# DLL, it's a .NET DLL. Once compiled, all you have is IL - doesn't matter what language it came from. Should be no problem, unless you encounter one of the odd edge cases where the DLL's interface includes something that is not supported by Visual Basic. But this would be very much an edge case.

The Common Language Specification, or CLS, defines the subset of .NET features that must be supported by a .NET language, and if your DLL is CLS compliant, then you can use it with no problems. If you are confused about the difference between the CLS, CTS, CLR etc, then I found the coverage of it in this book very helpful, though it is primarily a C# book.

David M
OP is asking about if that's *right thing* to do, as it already have that language mix in place
Rubens Farias
This is 95% - 99.99% true but not 100% true. That's why there is a Common Language Specification. Mark the DLL as CLS compliant, and that should 100% guarantee you can call it from any CLS language (e.g. VB.Net). http://stackoverflow.com/questions/2117776/mixing-vb-net-code-with-c-code/2117937#2117937
MarkJ
@Mark - thanks, I'm clearly not firing on all cylinders today. Guess that's why I'm not at work. Anyway, have edited the answer.
David M
... and then noticed you answer covers this very thouroughly as well. +1 from me.
David M
A: 

I think biggest danger is to have a developer to know both languages; while C# and VB.NET are similar because they're bound to .NET framework, they have some peculiarities.

You'll find many good C# programmers and many good VB.NET programmers, but can be a little harder to find a good programmer for both languages

Also, take a look into this article: A Manager’s Retrospective on the C# versus VB.NET decision as it talks about other items to keep in mind, as developer preferences, language features and recruiting.

Rubens Farias
Not me and not the other programmer working on that project, don't know at all vb language.So we really want to move to c# .
Night Walker
you could to reference that vb.net assemblies, just as you're already doing, and try to buy time with your boss to create a solution which uses a single language; you can justify that talking about productivity
Rubens Farias
A: 

One solution was found here:

However, it is possible to use different languages in a single project. You may need to write command line build file to build the project. In .NET framework SDK, there is one sample on it. You could access it in C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\CrossDevLan guage.

This sample demonstrates the use different development languages in a single project. This sample creates two assemblies. The first is a library or DLL assembly that defines a simple base class written in managed extensions for C++. The second assembly is an executable assembly that defines three derived classes written in C#, VB, and IL (Intermediate Language). These types derive from each other and ultimately from the base class written in managed C++. Finally, the executable creates instances of each of the derived types and calls a virtual method for each. The .NET Framework is an environment where various developers can work together seamlessly while developing in their language of choice.

But you can use both VB.NET and C# code inside asp.net application.

You need to create two folders (ex. vbFolder and csFolder) in App_Code folder and write this code in web.config:

<system.web>    
<compilation>    
<CODESUBDIRECTORIES>    
<ADD directoryName="vbFolder" />    
<ADD directoryName="csFolder" />    
</CODESUBDIRECTORIES>    
</compilation>    
</system.web>  

Good explanation is here.

sashaeve
A: 

Both VB.NET & C# are compiled to MSIL (Microsoft Intermediate Language) not native code and this to complete the full compilation to native (machine) on the end user machine via the exist .NET frame work which is on the end user machine so if it was .NET for operating system x your program should work fine for operating system x and if it was operating system y your application should work fine with OS y, and this is the solution which .NET technology comes with to let the .NET applications operating system in-Dependant.

also there is a COM Marshaler service to support old component (controls) to work with .NET applications so for example you can invoke vb6 control (*.ocx) in C# windows application.

and this is great integration between Microsoft technologies and techniques.

and no need to have developer good in both VB.NET and C#, but any way if you need one, I am here :)

but the question is why I am in both?

this just because I deliver training, So I thought to expand my abilities and I was surprised that they both very near except the syntax.

amr osama
+4  A: 

Mark your code as CLS compliant, and then the C# compiler will warn you if you do anything that might cause problems when your DLL is called from another .Net language.

Some quotes from MSDN

To fully interact with other objects regardless of the language they were implemented in, objects must expose to callers only those features that are common to all the languages they must interoperate with. For this reason, the Common Language Specification (CLS), which is a set of basic language features needed by many applications, has been defined.

You can mark assemblies, modules, types, and members as CLS-compliant using the CLSCompliantAttribute.

Some CLS-compliant language compilers, such as the C# compiler, enable you to specify that you intend your code to be CLS-compliant. These compilers can check for CLS compliance and let you know when your code uses functionality that is not supported by the CLS.

Also, your organisation will now need C# skills as well as Vb.Net skills. You should probably convince yourself that this is OK, and then convince key decision makers.

MarkJ