Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
2.00/5 (1 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
Comments
Sergey Alexandrovich Kryukov 14-Sep-12 2:57am    
What prevented you from reading on .NET in a regular manner, in addition to just Googgling? This is some very basic information.
--SA

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.
 
Share this answer
 
Comments
sahabiswarup 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?
Sergey Alexandrovich Kryukov 14-Sep-12 2:55am    
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
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.
 
Share this answer
 
v2
Comments
sahabiswarup 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?
Sergey Alexandrovich Kryukov 14-Sep-12 2:56am    
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
Sergey Alexandrovich Kryukov 14-Sep-12 2:55am    
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! :)
Sergey Alexandrovich Kryukov 14-Sep-12 2:59am    
Thank you. It's not missing anymore. Please don't hesitate to correct if the vote is forgotten.
--SA
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
 
Share this answer
 
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!
Sergey Alexandrovich Kryukov 14-Sep-12 3:06am    
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
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,
 
Share this answer
 
Comments
sahabiswarup 14-Sep-12 2:55am    
Nice article..Thanks for sharing
AmitGajjar 14-Sep-12 3:09am    
your welcome.
sahabiswarup 14-Sep-12 3:10am    
5 from me
AmitGajjar 14-Sep-12 3:11am    
Thanks
[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
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900