How can I create a type in vb.net and use the type in c#? I guess I need to compile the vb project and add reference to the dll but have no idea if this is the right way to do it, or the reference will be valid. Doing this is not for fun, we have some vb code and we're considering this option.
-
2Yes,you can make them class library and use them.Saman Gholami– Saman Gholami2013-03-06 14:15:52 +00:00Commented Mar 6, 2013 at 14:15
-
2Just add the project to your solution and add a reference. The languages of projects in a solution don't matter.John Willemse– John Willemse2013-03-06 14:18:52 +00:00Commented Mar 6, 2013 at 14:18
-
@JohnWillemse can they have a common namespace?Uğur Gümüşhan– Uğur Gümüşhan2013-03-06 14:20:32 +00:00Commented Mar 6, 2013 at 14:20
-
Jon is right, do it just like you had to deal with c# type - create a library and add a reference to it.cookieMonster– cookieMonster2013-03-06 14:21:11 +00:00Commented Mar 6, 2013 at 14:21
-
@UğurGümüşhan: They can, but it's generally better if you'd use separate namespaces for separate projects.Jon Skeet– Jon Skeet2013-03-06 14:22:05 +00:00Commented Mar 6, 2013 at 14:22
|
Show 1 more comment
1 Answer
Just create a Class Library project in VB, and then add a reference to that project from your C# project. (Or if it's in a different solution, add a reference to the DLL created by the VB project.) It should be absolutely fine - you'll have access to all the Public types from your class library.
To address the comment in your question, the projects can both default to the same namespace, but it's generally a better idea to make each project have its own namespace, so it's clear where any particular type comes from.