Using multiple programming languages in a ASP.net Web Application - c#

I've a Web Application project that uses VB as programming language. I want to keep using this language due I've more experience and also it works better with IntelliSense.
Anyway, now I am using Open XML SDK 2.0 Productivity Tool for generate code for the generation of a OOXML document through a given template, and this tool only generates C# code.
With the aim to mix both languages in my project, I had followed this tuto but when I try to add a new C# class, the only language that appears in the list is Visual Basic as you can see in the attached screenshot.
Does anyone know how I can fix this?
Thank you very much

This is not possible; you cannot mix C# with VB.NET in the same project. When .NET compiles an assembly it can use only one compiler to do so.
What you can do, is have a solution with multiple projects (for instance one Web app and several class libraries), and then you can have each class library in the language of your choice.

As others have said in general you cannot do this. The one exception is a web site project.
There is a difference between a web site project and a web application. Mainly in the way they are compiled. A web site is what the tutorial you linked talks about (note the way they say to create it via new website rather than new project and choosing web app) whereas you say above that you have a web application.
You have the option of either changing to a web site or using supplemental projects as others have suggested.

Mixing languages is not what I would go for.
Add a new (DLL)project to your solution that uses C# and handles your XML.
Reference that C# project from your VB-app and call into it.
Clean and easy.

You need to install Visual Studio for c#. It looks your current installed language is vb.
Here is link for downloading vs:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express
About using vb and c# code in same solution, its possible as long they are separated to different projects.

Related

So what does Microsoft CLR actually do? [duplicate]

I'm busy on a small project to convert an Access2003 db to .NET. I am trying to integrate my functionality in an existing project that is being used for Administration of some kind. The code in this project is VB.net.
I started by setting up my Data Access Layer, which seems to work fine. I can make new web pages that access the data I need. However when I start to use class files to set up my Business Logic Layer I can't build my project when using C# instead of VB. I dislike VB and like to program in C# as I know the syntax a lot better, etc. Is it possible to program using C# knowing that VB.NET was the language chosen to build the entire project on?
If not, what will be the smartest way to integrate my module into the project using my favorite programming language? (Make a project and reference to the dll?)
Edit: So the next step in my question would be -->
If I set up a new project within the existing solution, can I make that new project contain my Business Logic Layer + Data Access Layer and reference from my existing one?
Yes, you can't mix languages within the same project, but you can add as many projects written in different languages as you like, to the same solution. (This is sometimes very useful, especially when it comes to having portions written in C++/CLI, which are able to do things which would be impossible to do in C#/VB.NET.)

ASP.Net ASMX Webservice in Class Library (Best Practice)

i have a best practice question. I'm working on an Vb.net Webproject in Visual Studio. We are creating some modules that are defined in its own Class Library Project Folders. I want to bundle all files for this module within the project folder ... that include the WebServices.
I tried to define a WebService as in this HowTo described (http://www.dotnetwire.com/Articles/Class_Library_Project.asp) but i can't reach the WebService (404). Is this approach obsolete with IIS 7.5 or higher cause i found some postings on codeproject where other users have similar problems.
Is there a better way to "outsource" a webservice to its own library since when the upper HowTo was written ?
Greetings and thx in advance for help.
M. Lang
I think the general trend nowadays is to migrate away from the old .asmx services and toward REST. If you're using .NET the standard has been more and more ASP.NET Web API. Having said that, I develop my REST services in completely different solutions.

Easiest way to Implement Scripting to WPF C# Visual Studio 2015

I'd like some help in how to add scripting support to a WPF C# project I'm doing on Visual Studio 2015. One of the things I'd like to do is to be able to change User Control properties within that script. I've being trying Roslyn C#, and I read some stuff about IronPython and PowerShell Tools. But, all that information is not really helping.
So, do you have a simple answer? Like, the easiest way to execute scripts in Visual Studio 2015 C# WPF Application, that are able to change properties of User Controls within the project?
Any help would be appreciated.
Thanks,
Lucas.
T4 templates can help but they are less extensible than lets say Roslyn.
I found a great post on how to easily implement IronPython and how to access User Controls within the scripts in Python, so you can there change different Control properties, and even create them! Here's the link:http://www.codeproject.com/Articles/602112/Scripting-NET-Applications-with-IronPython
I think it should be quite simple to embed powershell or F# interactive in an application and there are lots of examples when we search the web for this. The question is only are we comfortable writing scripts in Powershell and F#?
In my application I provide a C# editor and compile scripts as static methods (which I uses as functions) using the standard .Net compiler API's which are installed with the framework (Microsoft.Csharp, System.CodeDom). This generates a temporary dll and perhaps can not be properly termed a script. The implementation is straight forward and more or less what you expect - I have to provide a way for the users to specify references and namespaces, then generate a source file, compile it to an assembly and then call members of the static class. This above technique works well because the application has extension points that are well adapted to user defined code with a certain well defined structure (you might have similar well defined needs and perhaps full scripting is not necessary).
On the other hand, I am considering providing a "super user" console where the application can be driven by script, and in this case, I will use either Powershell or F-sharp interactive (I'm leaning towards F#). I don't think the implementation is particularly complex, but these are things that can easily bring the application down or corrupt application data if it is not well controlled - and it is unlikely that my users will profit from scripting as it is a programmer environment.

Is it wrong to add razor (cshtml) and c# projects to a Visual Studio vb website?

I'm creating a new website in Visual Studio 2010 Ultimate / vb and I want to add things to it, to jazz it up. So I'm adding new projects from the VS Team Services templates. It seems there are many more projects in c# than vb. I'm trying to figure out if it's okay to add a c# and razor project to a vb website, because if not, I'll start the website in c#.
Will mixing languages between projects within your website present issues in the future when it comes time to build and publish? Or is it recommended I begin the website in c# (since there are more projects within VS) and keep the languages the same throughout the website? Thanks!
There is no issue in doing till you keep the projects separate. That is you should not write one controller in VB and another controller in C# in same project.
As far as i know there is no problem in keeping different projects in same solution
I think that is a great approach when you have a diverse skillset in your team, since some languages are better suited for specific tasks than others.
There sould be no problems with having different languages used in one solution (although you should use one langugage per project) since everything will be compiled into MSIL (some details can be found here).
A similar question was asked: Can you mix .net languages within a single project?
To add a bit more, I would never suggest anyone to mix two different languages. If you start with a solution with one programming languages, continue with that programming language even when you add new projects to that solution. There is nothing worse than having to switch your way of thinking from one language to another. We had a project at my former company where one project was C# and the other two were VB.NET. Maintaining those projects was a nightmare, not to mention a lot of subtle bugs in the way VB.NET and C# evaluate things like if statement.
My suggestion to you is choose one language and stick to it on your project. If you want to improve your knowledge in another language, work with that language, etc.

Possible to combine C#.net, VB.net and ASP.net?

I want to build a website in ASP.net, and to integrate a module which is written in C#(too complicated to rewrite in VB or ASP).
Now I just want to know whether it is possible to have a website that integrates all three?
Thank you.
Yes. You can have a WebSite integrating all three.
Just make your complicated C# a .NET library and include it in your VB.NET/ASP.NET project.
I think you only have to reference the dll's from your modules which are written in c# or VB to call your public functions. I've done this in a windows form application and it worked fine.
You may also want to consider simply learning C#. Most of what you know from VB.NET is directly usable in C#, since most work involves using framework classes and the languages share most features.
It is mostly a matter of syntactic preference, and while a new syntax may sting your eyes for a bit the learning curve will be steep and soon you will have left your old preferences behind.
You have a couple of options when integrating languages in ASP.NET. If you're creating a "web site" (as opposed to a "web application" which can use only one language) then each page can use a specified language, because essentially each page is compiled separately. Some can use VB, some can use C#. No problem.
However, what you describe sounds even simpler. You claim that there is an existing C# module which you want to use in your VB website. Is this module compiled into its own assembly? If that's the case then the language that was used to create the assembly is immaterial. Once it's compiled, it's a .NET assembly and can be referenced by any .NET language. It's no longer a matter of VB vs. C# (or any other language) once it's compiled.
If it's not a compiled assembly, but rather a bunch of class files, can it be compiled as its own assembly? That's generally good for keeping things modular. Within a single .NET solution you can have each project use different languages without problem. This module can be a library project written in C# and your site can be a web site (or web application) project written in VB, which references the library project.
Since all these assemblies ultimatly use the same CLR (hence the name Common Language Runtime), they can be used together with no problem.

Categories

Resources