Link to home
Start Free TrialLog in
Avatar of Moonsaver

asked on

How do I call vB methods inside C# in App_Code folder, same project?

I have a project that was made in VB by another programmer, and I need to work on that project in C# (since I have no knowledge of VB).

The project is structured as follows :

- Admin
** Test.aspx
- App_Code
-- CS_Code
** Object1.cs
-- VB_Code
** Object2.vb

 When I am in "Object1.cs", how do I create the object "Object2" that is located in the App_Code/Vb_Code folder?

Object2 = new Object2();

It does not see the Object2 at all.
Avatar of abel
Flag of Netherlands image

Place a "using" directive in the top of your Object1.cs. Code from different languages MUST reside in different assemblies. So, likely, your Namespace directives are different for the VB assembly.
Avatar of Moonsaver


I have tried the following :

In "App_Code/CS_Code/Class1.cs" :
namespace CS
    public class Class1
        public Class1()

In "App_Code/VB_Code/Class2.vb" :
Imports Microsoft.VisualBasic
Namespace VB
    Public Class Class2
    End Class
End Namespace

I can't access Class2 inside Class1. I tried "Using VB;" and it does not find the namespace.
My apologies, I think I missed your point. You have different codeSubDirectories, right? With different languages. These cannot access one another, because there's officially no compiler dependency between the differen directories.

Not really an explanation, but still an answer, is here:

I used to have these codeSubDirectories because some things are just easier in C#. Now I remember why I removed them one day and placed them in a separate project.

Sorry that I didn't have any better news for you ...

-- Abel --
What do you suggest for me to do in the scenario that "Class1" requires "Class2" to work?
Avatar of abel
Flag of Netherlands image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that if Class1 remains in the web application and Class2 goes into its own projects, that Class2 cannot access any members from Class1. However, Class1 *can* access as much members from Class2 as are public.

Circular dependencies are never allowed anyway (you'll need Java or Eiffel for that).
Tx for the points, hope you get it working!