DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Cross Language References in ASP.NET

Dave Bush user avatar by
Dave Bush
·
Jun. 16, 12 · · Interview
Like (0)
Save
Tweet
3.72K Views

Join the DZone community and get the full member experience.

Join For Free

ppl-crwd-018

Most ASP.NET programmers are aware that the environment allows programmers to write code in multiple languages.  This is what allows a programmer who prefers CSharp to write modules for DotNetNuke in CSharp even though the core code is written in VB.NET.  (Until version 6.0, anyhow, where the core will finally be written in CSharp.)

What many don’t realize is that you can’t have CSharp code reference VB.NET and also have VB.NET code reference the CSharp code within the same application.  At least, you can’t do it directly.

The project I’m working on is primarily written in VB.NET.  It’s the 5.x version of DNN.  Right before they moved the core to CSharp.   All of my code is written in CSharp.  So my code can reference the core without any trouble.  This is because each language produces its own DLL and you can’t have two DLLs reference each other because that would cause a circular reference.

When you need to have DLLs reference each other, you need to use reflection from one of the two DLLs to reference the code in the DLL that can’t be accessed directly.

Most of the articles I found on the web stop with that explanation.  Actually, most of them don’t even bother to mention that using reflection is part of the solution.  The question I spent more time trying to find the answer to than I would like is, “How do I dynamically load an assembly that is produced from an App_Code subdirectory and that will have a somewhat random name?”

Here’s the line of code  you need:

System.Reflection.Assembly.Load(<font class="str">"App_SubCode_"</font>+ appCodeSubDirectoryName)

This returns a System.Reflection.Assembly object and from there you can use reflection like you would anywhere else.  If you need information on how to do that, I’ve written about that on other places on this site.

ASP.NET

Published at DZone with permission of Dave Bush, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Removing JavaScript: How To Use HTML With Htmx and Reduce the Amount of Code
  • Top 10 Criteria to Select the Best Angular Development Company
  • Salesforce and Snowflake Native Data Integration Options
  • AWS Serverless Lambda Resiliency: Part 1

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo