简体   繁体   中英

How can you reference code written in another language in the App_Code folder in ASP.Net?

Due to legacy issues I have two folders under App_Code directory. One for VB.Net and another for C#. Problem is, I have a service in the C# folder that needs to leverage a class in the VB.Net folder but they dont seem to know about each other. Any ideas are welcome :)

Thanks in advance!

Trev

I had this same problem and ended up having to move the code to a class library and not use App_Code, so my answer is:

Unless someone has a solution for you, move your code that needs to be seen by both into a separate class library project.

Here is a very good example about mixing C# and VB in the same Web project...

The trick is done using the codeSubDirectories compilation element in your application's Web.config, to define code directories that will be compiled into separate assemblies at build or run time...

Here's one approach: http://www.aspnetlibrary.com/articledetails.aspx?article=Use-C-Sharp-and-VB.NET-in-the-same-project .

See also: Can you mix .net languages within a single project? .

If you're already set up as described in the article and the problem is calling one App_Code sub-directory from another, you have to refactor a bit. You mention it's a service calling the other sub-directory. Consider moving the service's code-behind to the same directory as its .asmx. That way, it can use code from anywhere in App_Code. If your service is in the wrong language for the project, you'll have to re-write it.

Maybe consider translating your VB code into C#? This has the added benefit of making your project more consistent and maintainable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM