Click here to Skip to main content
13,147,376 members (28,662 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
There is a web application which is codded using VB, now i want to add some new pages and i am using C#; after adding my cs class in App_code folder it is not working.

Can anyone tell how to add cs class in VB web application?
Posted 13-Sep-12 20:39pm
Comments
   
What prevented you from reading on .NET in a regular manner, in addition to just Googgling? This is some very basic information.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can't mix c# and vb.net in one project. What you can do is to add the c# code to its own project which is inside your vb.net solution. That works very well.
  Permalink  
Comments
biswarup88 14-Sep-12 2:45am
   
That VB project is older one; i have to add some newer forms so how do i do that? can you please suggest?
   
Formally speaking, it's true (my 5), but I suspect that OP does not know how to develop some code in different languages in principle.

I tried to explain that in my answer, please see.
--SA
Sergey Alexandrovich Kryukov 14-Sep-12 14:07pm
   
After a bit more thinking, I realized that your answer is, strictly speaking, incorrect. (But I already voted, it's OK :-)

However, the way to overcome this limitation is highly customized and very advanced. So, I don't think it could be really practical. Nevertheless, this is something which is really good to know, not just for the reasons related to this question.

Please see my other solution (Solution 5).
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

AFAIK, you can not. Projects are either VB.NET or C#. You can use compiled assemblies written in either language, but you can not just mix the code.
If you want the web application that is currently in VB to have it's code behind compiled into the same assembly as the C#, then I you will have to convert them.

UPDATE:
Good to know that this is quite possible. Placing files in different folders with defined names in App_Code does the trick.
  Permalink  
v2
Comments
biswarup88 14-Sep-12 2:47am
   
After googled i have found that in windows application vb and C# can work in a same project; is there no such option through which i can run both?
   
No. I think you mix up different thing. In one application -- yes, but the application can be built in more then one project, and the languages for different project can be different. I explained it in my answer.
--SA
   
Formally speaking, it's true (my 5), but I suspect that OP does not know how to develop some code in different languages in principle.

I tried to explain that in my answer, please see.
--SA
Sandeep Mewara 14-Sep-12 2:58am
   
Thanks. BTW, your 5 is missing... but my 5 is on the way to your answer! :)
   
Thank you. It's not missing anymore. Please don't hesitate to correct if the vote is forgotten.
--SA
biswarup88 14-Sep-12 3:04am
   
finally i've found what i want: Please check this following link
http://virendradugar.wordpress.com/2009/06/15/using-c-and-vb-net-classes-together-in-the-app_code-folder/
Thanks to @amitgajjar for sharing this and virendradugar for posting this
Sergey Alexandrovich Kryukov 14-Sep-12 14:09pm
   
Yes, this is good to know, but this is not it. After some thinking, I realized that there are ways to use different language in one project, but they are might be too customized and advanced to be practical. Please see my new Solution 5.
--SA
Sergey Alexandrovich Kryukov 14-Sep-12 14:08pm
   
Sandeep,

After a bit more thinking, I realized that your answer is, strictly speaking, incorrect. (But I already voted, it's OK :-)

However, the way to overcome this limitation is highly customized and very advanced. So, I don't think it could be really practical. Nevertheless, this is something which is really good to know, not just for the reasons related to this question.

Please see my other solution (Solution 5).
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Essentially, there is no such thing as "C#" class. There are CLI classes, that's it. You can write one assembly in one language, and then reference it in some other .NET language. If you use Visual Studio, each assembly would be a separate project, and you can reference one project from another withing the same solution (highly recommended, because this also automatically resolves changes in versions, strong names and the dependencies; during run time, the assemblies reference each other, not projects).

So, there is no boundaries between languages, and the boundaries between assemblies are so transparent, the the development process does not give you any hassles, so development of a multi-project solution is going in exact same way as in the case of a single monolithic process.

Just in case, I should mentioned (even though this is beyond the question), that some language provide additional feature which can go slightly beyond standard .NET feature. For example, C++/CLI allows for value semantic for reference types.

I must note that this question is based on insufficient reading on most general and basic platform topics you needed. You certainly need to read some more. Please start with this:
http://en.wikipedia.org/wiki/.NET_platform[^],
http://en.wikipedia.org/wiki/Common_Language_Infrastructure[^],
http://en.wikipedia.org/wiki/Clr[^],
http://en.wikipedia.org/wiki/Managed_code[^],
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[^].

You also need to read on matching topic in MSDN.

This is less then the minimum required for successful development, but it will just give you the idea on key concepts.

Good luck,
—SA
  Permalink  
v3
Comments
Sandeep Mewara 14-Sep-12 2:58am
   
Thanks for filling in the gap SA(that looked like present post OP's comment to my answer) .... My 5!
   
Thank you, Sandeep.
As to the filling the gap -- this is teamwork. You filled another gap, too, thank you.
--SA
@amitgajjar 14-Sep-12 3:08am
   
Nice information 5+
Sergey Alexandrovich Kryukov 14-Sep-12 13:36pm
   
Thank you, Amit.
--SA
Sergey Alexandrovich Kryukov 14-Sep-12 14:11pm
   
Yes, thank you very much, but...
I later realized that there is more to it: actually, it's possible to use different languages in one project, but these are highly customized and advanced ways.
Please see my new Solution 5 -- this is something good to understand.
--SA
@amitgajjar 14-Sep-12 23:12pm
   
I also want to add one more word "dynamic" with this discussion. we can execute some functions from dynamic languages like python and ruby using dynamic in FW4.0

So embedding such dynamic languages could be possible in VB/C# project.
   
Embedding?.. But do the dynamic languages have to come in a separate project?
--SA
@amitgajjar 15-Sep-12 1:43am
   
No, Just create one python class file or create string within code like this

So what we need to do is, we need to add one .py file in our code as we add image file and utilize it through dynamic keyword!!!!
Sergey Alexandrovich Kryukov 16-Sep-12 23:49pm
   
Interesting; I never tried it. Would be good to try. Well, then this is yet another mechanism for this kind of languages. Thank you for sharing.
--SA
@amitgajjar 17-Sep-12 0:53am
   
Your always welcome.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi,

You can store your C# code in App_code folder, hope you have done some minor mistake.

Check this article[^].

You need to create seprate folder in app_code to get your work done. Let me know if it works for you,
  Permalink  
Comments
biswarup88 14-Sep-12 2:55am
   
Nice article..Thanks for sharing
@amitgajjar 14-Sep-12 3:09am
   
your welcome.
biswarup88 14-Sep-12 3:10am
   
5 from me
@amitgajjar 14-Sep-12 3:11am
   
Thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

[This is the advanced follow-up answer in response to Solution 1 and Solution 2]

Strictly speaking, the statement "you can't mix C# and VB.NET in one project" is not correct at all. It is quite possible, but may be impractical and overly complicated. So, for all practical purposes, it's much better to develop code using multiple projects each using a single language and producing a single assembly, each assembly represented in a single executable module. This is just not the most general case.

Now, as I say that "you can't…" statement is wrong, I need to explain how mixing languages in one project is possible. Yes, it is possible. There are two key facts to it:

#1:

It depends on what is called a "project". If it is created by Visual Studio in a standard manner, this is one thing. But, strictly speaking, "project" is something written using the MSBuilt project XML schema and valid semantically. Every one can write such project in a custom way and even develop custom "Tasks" implementing required BSBuild interfaces (http://msdn.microsoft.com/en-us/library/ms171466.aspx[^], http://msdn.microsoft.com/en-us/library/t9883dzc.aspx[^]). In particular, a custom task can make direct use of C#, VB.NET or any other compiler to use additional features of them, not presently used by Visual Studio; also the custom project can simply use those compilers directly though the command line — there is a standard task to execute any application and pass a command line parameter line to it, so one can also use those additional compiler features.

Now, we are coming to the second fact: what "feature" will allow to use more then one language in the same project? But before we discuss it, I want to mentioned yet another opportunity to formally overcome the limitation "single language per project".

As the project can be custom, the nature of the project can be made different from what is used in Visual Studio. In other words, in particular, a project can play a role of the solution and still produce one language per assembly each composed on one executable module, but produce more then one assembly each written in its own language. The difference is just formal: the result is the same as with solution, only under the umbrella of a single project. This is something which is used by some, usually called a "superproject". For example, for the sake of automatic build and support of complex system I personally uses a superproject integrated several solution, each solution actually used as a separate "view" on the code base.

Now, coming back to "additional feature" not used by Visual Studio:

#2:

Visual Studio only supports the special-case simple model where each assembly is just one file. But — look at Reflection — an assembly is composed of executable modules, and each module is not an assembly. So, this model is a model using one executable module per assembly. If one uses a compiler in a custom way, this developer can use a more general feature each compiler is obliged to implement, to be compatible with CLI requirements: creation of separate executable modules (but not assemblies, each such module is a separate filesl the modules can not be executed by themselves in a general case) and adding existing module to assembly. This way, each module could be written in a different language, a single assembly could be produced by a single project, but such project could use different languages. This is what was required to proof.

I hope I've finally clarified this tricky subject.

—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100