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 .
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With