Using a VB class from the same ASP.NET website project in a C # class

I have an ASP.NET website project where I use VB.Net and C # class files. I have included separate subfolders in the App_Code directory for the classes of each language.

However, although I can successfully use the C # class in the VB class, I cannot do the opposite: use the VB class in the C # class.

So, to illustrate, I can have two such classes:

Public Class VBTestClass
    Public Sub New()
    End Sub

    Public Function HelloWorld(ByVal Name As String) As String
        Return Name
    End Function
End Class

public class CSTestClass
{
    public CSTestClass()
    {
    }
    public string HelloWorld(string Name)
    {
        return Name;
    }

}

I can use the CS class in my VB class with the Import statement. So this works well:

Imports CSTestClass
Public Class VBTestClass
    Public Sub New()
    End Sub

    Public Function HelloWorld(ByVal Name As String) As String
        Return Name
    End Function

  Private Sub test()
      Dim CS As New CSTestClass
      CS.HelloWorld("MyName")
   End Sub
End Class

But using the VB class in my C # with the using statement does not work:

using VBTestClass;
public class CSTestClass
{
      public CSTestClass()
      {
  }

     public string HelloWorld(string Name)
    {
        return Name;
    }
}

I get the error "Unable to find the type or namespace VBTestClass." What am I missing here?

+3
4

, , , , .

, , CodeSubDirectories, , :

<codeSubDirectories>
    <add directoryName="CSCode"/>
    <add directoryName="VBCode"/>
</codeSubDirectories>

, , .

, CSCode, , VBCode, CS , .

, , VB CS, CSCode, VBCode , .

, CS VB, :

<codeSubDirectories>
    <add directoryName="VBCode"/>
    <add directoryName="CSCode"/>
</codeSubDirectories>

CS- VB, VBCode.

, , , .

, .

+2

/ , . vb #.

:

qualyfying:

void DoSomething()
{
    var p = new Interfaces.CPDATA.DataHolders.Placement(); 
}

:

using Interfaces.CPDATA.DataHolders; 
void DoSomething()
{
    var p = new Placement(); 
    var t = new Trade(); 
}    

using data = Interfaces.CPDATA.DataHolders; 
void DoSomething()
{
    var p = new data.Placement(); 
    var t = new data.Trade(); 
}   

:

using t = Interfaces.CPDATA.DataHolders.Placement; 
void DoSomething()
{
    var p = new t(); // happy debagging
}   

ASP.NET App_Code: . :

  • -
  • csc vbc Visual Studio
  • , , .

- .

, visual studio iis . , ,

\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\{project name}\{tempname} 

, asp.net aspx.

, , CSTestClass " CSTestClass" . , MyWebProject.VbCode MyWebProject.CsCode, . "using MyWebProject.VbCode" "Imports MyWebProject.CsCode" .

+1

using , , VBClass "using":

Namespace MyFoo
Public Class VBTestClass 
    Public Sub New() 
    End Sub 

    Public Function HelloWorld(ByVal Name As String) As String 
        Return Name 
    End Function 
End Class
End Namespace

#:

using MyFoo;

...
0

, Imports using.

using , Imports .

, Imports CSTestClass , , , , Imports .

using VBTestClass, , VBTestClass .

, Imports using, . , .

0

Source: https://habr.com/ru/post/1756203/


All Articles