C# and VB.NET playing nice in the ASP.NET 2.0 Playground

Published Wed, Mar 30 2005 20:11 | William

I've been finding so much cool sh1t in the newest build of Whidbey that it's hard to keep up.  It's really amazing how, when you actually have to build something professionally, you come across so much more than you ever would just tinkering through it.  Well, I was editing my web.config file and saw some neat stuff on the <compilation> node.  It got me to wondering what all was happening with it and after  a little investigation, I found out about the “\Code” folder.  I'll explain more later on what Code is all about, but suffice to say that if you try to add a Class to your web site, it will recommend you put it in code.  The dialog that pops up will allow you to choose your language (J#, C# or VB.NET) which is a big clue that you can do something cool.  So in  a nutshell, you can have VB.NET and C# source code, sitting IN THE SAME ASSEMBLY!!!! and they'll play nice together.  It takes a tiny bit of tweaking in the config file, but even a VB6 programmer can handle it.  First, for each language, you need a directory under the Code folder.  You can get pretty nice from there so don't think that it's stopping you from organizing your code.  I made two directories named surprisingly enough, CSharpStuff and VBStuff.  Then I added a directoryName for each of them:

 

After that I added a C# class underneath the CSharpStuff folder and some VBCode under the VBStuff folder (and yes, if I wanted to be cute I could have put CSharp code in the VB folder and vice versa and it would work).  NOw, the neat part is that they are visible to each other - so namespaces aside, CuckooConcrete directly inherits from CuckooBase:


 


Comments

# William said on April 3, 2005 12:05 PM:

Hey Bill, which release are you trying this on? It looks cool and I can get it to compile but I can't get the two classes to see each other (so no inheritance or reference from one to the other compiles). I even tried defining them both in the same|different namespace, still no luck. If you haven't missed any steps in your description would you be able to zip/email me the solution? Cheers!

# William said on April 3, 2005 12:08 PM:

Daniel - I'll gladly zip it over to you when I get home - but the key to being able to see each other is just to build it once. After you do the intial build - they should be able to see each other. I have the latest beta installed - I'm not at home so I don't have the version number but I'll zing it to you later.

# William said on April 8, 2005 4:47 PM:

Thanks Bill. Looking forward to receiving the zip so I can play "spot the difference"...

# William said on April 8, 2005 4:57 PM:

Daniel - I'll be home in about 2 hours, I'll send it over then. Let me know if you have any questions once you get it.

Cheers man,

Bill

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications