Monday, March 26, 2012

Mixed Language Development

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
--

AG
Email: discuss at adhdata dot comWhich 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.

"AG" <NOSPAMa-giam@.newsgroups.nospamwrote in message
news:eClPNi0RHHA.4832@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>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
--
>
AG
Email: discuss at adhdata dot com
>
>
>
>
>


Thanks for the reply Mike.
I am using VS 2005.
I am referring to mixed language development within the same project.
VS 2003 did not support that.

According to this article
http://msdn2.microsoft.com/en-us/library/ms366714.aspx
it should work.

--

AG
Email: discuss at adhdata dot com

"Michael D. Ober" <obermd.@..alum.mit.edu.no.spamwrote in message
news:xIdxh.20472$w91.18219@.newsread1.news.pas.eart hlink.net...

Quote:

Originally Posted by

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.
>
"AG" <NOSPAMa-giam@.newsgroups.nospamwrote in message
news:eClPNi0RHHA.4832@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>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
>--
>>
>AG
>Email: discuss at adhdata dot com
>>
>>
>>
>>
>>


>
>
>


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.

"AG" <NOSPAMa-giam@.newsgroups.nospamwrote in message
news:ehqyz6FSHHA.4632@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

Thanks for the reply Mike.
I am using VS 2005.
I am referring to mixed language development within the same project.
VS 2003 did not support that.
>
According to this article
http://msdn2.microsoft.com/en-us/library/ms366714.aspx
it should work.
>
--
>
AG
Email: discuss at adhdata dot com
>
>
>
"Michael D. Ober" <obermd.@..alum.mit.edu.no.spamwrote in message
news:xIdxh.20472$w91.18219@.newsread1.news.pas.eart hlink.net...

Quote:

Originally Posted by

>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.
>>
>"AG" <NOSPAMa-giam@.newsgroups.nospamwrote in message
>news:eClPNi0RHHA.4832@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>>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
>>--
>>>
>>AG
>>Email: discuss at adhdata dot com
>>>
>>>
>>>
>>>
>>>


>>
>>
>>


>
>
>


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/subscript...ault.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/subscript...rt/default.aspx.

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

This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks Steven.
At least I know what is going on. The article
http://msdn2.microsoft.com/en-us/library/ms366714.aspx is misleading.

Since most of my classes will be VB, I will probably convert the C# classes
to VB.

--

AG
Email: discuss at adhdata dot com

"Steven Cheng[MSFT]" <stcheng@.online.microsoft.comwrote in message
news:j4wUXnOSHHA.3792@.TK2MSFTNGHUB02.phx.gbl...

Quote:

Originally Posted by

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/subscript...ault.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/subscript...rt/default.aspx.
>
==================================================
>
>
>
This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
>


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/feedba...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.

0 comments:

Post a Comment