This question already has answers here:
How to call a function written in VB from C# application
(3 answers)
Closed 1 year ago.
I wonder if you can open a VB.NET form1 from C# form1
like VB.NET Form1.Show(); inside the button function of the C# code. I just thought of this will trying learn various code in them, can someone help to verify if this is possible???
The answer is Yes, but you can't have C# and VB.net in a single project. So create a solution containing two projects, one in C# the other in Vb.Net and you can open the vb.Net project form in C# as you suggest.
There is one major consideration though - that's dependencies. For this to work, the vb.net project is a dependency of the c# project, so the C# project sees all the VB.Net project but not the other way around.
It is possible to configure the solution to make both projects reference eachother - here's a post about it. Reference in two projects
However that's complicated and so I'd suggest having a third project (or fourth if needed) that contains any code you want to have common to both the VB and C# projects as a dependency to them both.
Related
I just installed VS 2017 a couple of days ago.
Normally I work in C#.
However, I have one project that was written in VB.Net.
I want to pull out a selection of VB procedures and functions and put them in a static class.
However, when I try to add a new Class to the project it only gives me the option of a C# class, no VB at all.
Yes I could convert the VB code to C# but that is a lot of work and I don't want to do it since I shouldn't have to.
Has anyone encountered this and if so did you find a solution?
Thanks.
C# and VB.Net can coexist in the same solution, but not the same project. You can add a second project to your solution. Make it a VB.Net class library. Add any VB.Net modules to the new class library. Add a reference in your C# project to the VB.Net class library. Build all and enjoy!
If you do decide to translate from VB.Net to C# to keep things cleaner, I have had good luck with the code translator found here: http://converter.telerik.com/
This question already has answers here:
How to merge multiple assemblies into one?
(7 answers)
Closed 6 years ago.
I tried using a server that gives me a DLL which I can use to make a game server code(in a dll project), upload it and let them host the game for me, but here's my problem:
I used an extra dll reference (in addition to their dll reference) when I made the game server code and when I tried to upload it, it said that I can only use their dll. So my question is, how can I hide the extra reference I used?
EDIT: I'll try to merge it or something. If it doesn't work that's it. Question closed. Thanks!
If their service requires you to only use their DLL. Then they are serious when they say only use their DLL. They probably did this to avoid complications in some form or another. The only thing I could think of is combining the DLL's together with mkbundle.
mkbundle -o Name.dll targetOne.dll targetTwo.dll
This will create static copies of the DLL's inside of the Name.dll. However im sure they would have a system to check for this.
This question already has answers here:
C# library to native C++ application
(3 answers)
Closed 3 years ago.
What is the best solution to access c# code via native code (C++)?
I have C# code which I want to call from native project, so I'm considering writing a COM wrapper but I wonder whether there is a better option (framework/design pattern/architecture etc.) available in .NET?
COM interop is without a doubt the best bet. It's a known, supported framework for achieving exactly what you want to achieve.
There is another alternative however - it is possible to edit the IL code inside a compiled .NET assembly to flag methods within the assembly as native exports. A detailed breakdown of the changes can be found in this CodeProject article.
Robert Giesecke has created Unmanaged Exports to simplify this process using simple method attributes. A NuGet package can be found here.
I am using asp.net 2012 and have c# class project where I would like to include some existing vb.net classes.
What would be the best way to be able to use both c# and vb.net classes?
Either convert the vb.net classes into C# or put the vb.net classes into their own assembly and add a reference to the assembly.
put the VB.NET classes in a project of its own and then reference that project, just as you would any third party control.
As already mentioned, one of the alternatives is to convert c# to vb.net or vice-versa.
You can find many pages in the internet to do that, like these ones:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
http://www.developerfusion.com/tools/convert/csharp-to-vb/
If you convert the code from one language to the other make sure you test the changes properly.
If you decide to keep VB.NET code in a separate Visual Studio project and reference it in the C# code you need to ensure that the VB.NET code is CLS compliant. This is a good starting point:
Writing CLS-Compliant Code
See also:
Cross-Language Interoperability
Make C# a .NET library and include it in your VB.NET/ASP.NET project.
Follow this http://msdn.microsoft.com/en-us/library/t990ks23.aspx for more info...
This question already has answers here:
Mixing C# & VB In The Same Project
(17 answers)
Closed 5 years ago.
I am working on an asp.net(c#) project for a client. He wanted to add one more team member and that person want to write code in VB.net. So is that possible that for that same project we have pages with different languages ??
It's possible, kind of. Instead of saying how though, I'm going to say why it's a terrible idea (usually):
The C# programmer will have to get warmed up to VB.Net when a bug is found there
The VB.Net programmer will have to get warmed up to C# when a bug is found there
Sure, you could maybe pretend that each programmer will "own" the code and will never have to deal with the other language... but then
You determine you need another programmer
So, in most cases DON'T DO THAT! Instead, choose one of the other. VB.Net is fine, C# is fine. But mixing them in the same project is stupid and just leads to confusion and frustration
Now, that being said, there are exceptions. Visual Studio doesn't allow for one of intermix languages in a single project, so this basically means you're forced to make the different language portion be a separate library. This is recognized as a shortcoming in Visual Studio, but really, for the reasons said above, this is why this isn't supported(probably).
So, If you're considering using two different languages, ensure the following:
They are separate enough for one to be a library
You'll actually gain some value from using another language (for instance, writing a very stateless and asynchronous library, would benefit from F#)
If #2 isn't satisfied, then ensure that programmers in one language should rarely need to touch the library in the other language. (hint: usually not the case)
It's not possible to combine files in different languages in a single project. You can, however, add a project in a different .NET language to your solution.
This may be appropriate if you are adding utility code which you intend to reference from your main project. However, doing it to extend the functionality of an existing application or web site is likely to cause you a lot of headache.