"You can create assemblies consisting of types implemented in different programming languages. […]"
I'm not certain that this actually adds much value in real-world scenarios, (a) because Visual Studio doesn't support project references to netmodules, and (b) because you can get the same benefit with assemblies.
There's one notable difference between a multi-assembly and multi-file assembly approach: One assembly cannot by default access another assembly's types that have internal
/Friend
(i.e. assembly) visibility. If you were compiling to modules instead and then link them into a single multi-file assembly, a module compiled from C# could access internal
types of a module compiled with VB.NET (and vice versa).
You'll find a brief demonstration of this below.
CsharpClass.cs:
internal class CsharpClass { }
VbClass.vb:
Friend Class VbClass : End Class
Program.cs:
public static class Program
{
public static void Main()
{
var vbClass = new VbClass();
var csharpClass = new CsharpClass();
}
}
Build script for netmodules:
csc.exe /t:module /out:CsharpClass.netmodule CsharpClass.cs
vbc.exe /t:module /out:VbClass.netmodule VbClass.vb
csc.exe /t:exe /out:Program.exe /addmodule:CsharpClass.netmodule /addmodule:VbClass.netmodule Program.cs
This build will work and execute without any errors.
Note that there is nothing magical about the .netmodule
file extension; this is only a convention, but the output file is a regular .NET DLL.
Build script for assemblies:
csc.exe /t:library /out:CsharpClass.dll CsharpClass.cs
vbc.exe /t:library /out:VbClass.dll VbClass.vb
csc.exe /t:exe /out:Program.exe /r:CsharpClass.dll /r:VbClass.dll Program.cs
This build will fail because:
Program.cs(5,27): error CS0122: 'VbClass' is inaccessible due to its protection level
Program.cs(5,23): error CS0143: The type 'VbClass' has no constructors defined
Program.cs(6,31): error CS0122: 'CsharpClass' is inaccessible due to its protection level
Program.cs(6,27): error CS0143: The type 'CsharpClass' has no constructors defined