Mixed Language Development

A

AG

I am working on a web app using both C# and VB. Yes, there is a reason for
it.

All the code behind is C#.
In the web.config I have the following

<compilation debug="true">
<codeSubDirectories>
<add directoryName="VB_Code"/>
<add directoryName="Csharp_Code"/>
</codeSubDirectories>
</compilation>
There are public classes in the appropriate folders of each language type.
I can reference any class from the pages' code behind.
I can reference VB classes from the C# classes in the App_Code\Csharp_Code
folder.
I can reference VB classes from other VB classes.
I cna reference C# classes from other C# classed.

However I can't reference any C# classes from the VB classes in the
AppCode\VB_Code.
The error indicates that the class is not defined.

Can anyone explain this and possibly tell me how to reference the C# classes
from the VB classes?

TIA
 
M

Michael D. Ober

Which version of Visual Studio. I have a mixed language web-site under
development (VB, C#, and a little JScript) and I reference all three
languages with no problem. Note, your VB projects need to be DLL projects.

Mike Ober.
 
M

Michael D. Ober

Even with these changes, each assembly is still limited to a single language
and I think that's what you're running into. The site I'm developing
doesn't make the language specific support in the MSDN article - the site
itself is in C# and I have C# and VB assemblies behind it.

Mike.
 
S

Steven Cheng[MSFT]

Hello AG,

As for the mixed language problem you mentioned, it is actually due to the
natural limitation of .net framework's assembly referencing. In .net
framework, when you have two assemblies(suppose they're A and B), then
there are only two possible referencing topology. They are:

A reference B(B is referenced by A)

or

B reference A(A is referenced by B)

Two assembly can not reference each other at the same time(cross reference
is not allowed).

For your scenario, you use mixed languages to create custom class in
ASP.NET 2.0's App_code folder(by separate them into own sub directories),
though ASP.NET 2.0 support this pattern, it will actually compile those
classes(of different programming languges and in different sub folders)
into separate assemblies. As the same as above, only one assembly can
reference the other one. Here your CS classes(in cs_subdir) will be
compiled into a dynamic assembly(suppose is named dynamic_cs.dll), your VB
classes will be compiled into another assembly(named dynamic_vb.dll), so
the only supported referecing cases are:

dynamic_vb.dll reference dynamic_cs.dll(VB classes can use CS classes)

dynamic_cs.dll reference dynamic_vb.dll(CS classes can use VB classes)

I haven't got any more detailed info about how the runtime will compile the
sub directories(under App_Code), and make the reference relation ship, but
only one of the above condtions will be allowed.

Also, based on my understanding, the "App_Code" directory help to provide a
"dynamic class library" functionarlity, so each class in App_Code should be
treated as a class library, we should not rely on they can see the
other(unless they are of the same language and can be compiled into the
same assembly). The ASP.NET 2.0 application will always ensure all the page
and usercontrol can correctly reference those classes in App_Code folder.

If you do need to have full control over the reference relationship, I
would suggest you consider move some of the classes into a class library
project so that they can be precompiled into an assembly and be referenced
by the ASP.NET project. How do you think?

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your reply AG,

yes, the MSDN article you referenced mainly talk about referencing
multi-language code (in App_Code) from ASPX page's code, and hasn't
detailedly explain the underlying compilation structure and process.

Also, I really recommend that you submit the feedback for the document. You
can post feedback for the document through two means:

** In the document page, you can find the a bar of stars on the right top
corner, hover the mouse over it and you can submit optional feedback on
this.

** You can also directly submit feedback or request to the MSDN product
feedback center:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Any of your comments are really appreciated.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top