Visual Studio.NET and the .NET Framework

Magnus Österberg

Matriculation #24488

Department of Computer Science
Åbo Akademi University

FIN-20520 Turku

Finland


e-mail:
URL: http://www.abo.fi/~ magnus.osterberg

Table of contents

1. Introduction

1.1 Abstract…………………………………………………………………..3

1.2 Keywords ………………………………………………………………..3

1.3 Classification……………………………………………………………..3

2. .NET Overview

2.1 .NET in general………………………………………………………….4 2.2 Microsoft.NET…………………………………………………………..5 2.3 The .NET platform………………………………………………………6

2.4 Language integration and language independence………………………7

2.5 Deployment and installation of .NET software………………………….7

3. The .NET Framework

3.1 The .NET Framework architecture……………………………………………8

4. Development using the .NET architecture

4.1 One language – one API………………………………………………….9

4.2 A few .NET code examples………………………………………………11

4.2.1 Hello World in Java……………………………………………..11

4.2.2 Hello World in C++……………………………………………..11

4.2.3 Hello World in VB.NET…………………………………………12

4.2.4 Hello World in C#...... …13

4.2.5 Hello World in Managed C++……………………………………13

4.3 Conclusion………………………………………………………………….13

5. References……………………………………………………………………………14

Appendix A: Common acronyms………………………………………………………15

1. Introduction

1.1 Abstract

This paper will discuss Microsoft’s .NET technology, the architecture behind .NET, programming in the .NET environment, and the framework enabling a language independent project management philosophy.

I will try to cover a wide area of the architecture. Due to limitations in length of similar papers, some things will be discussed only briefly. References and links will be provided where there is need. My website 1) will contain downloadable example applications, the source code will also be available.

1.2 Keywords

Keywords defining this paper:

Visual Studio.NET, .NET architecture, .NET Framework, Common Language Infrastructure,

Common Language Runtime, Common Language Specification, Dynamically Linked Library, Extensible Markup Languag, XML

1.3 Classification

The classifications given below assists the reader in finding more information on this topic.

Classification by ACM:

D.3.3 Language Constructs and Features Frameworks

http://www.acm.org/class/1998/D.3.3.html

Classification by SIG:

Special Interest Group on Programming Languages

http://www.acm.org/sigplan/

1) http://www.abo.fi/~magoster/studies/seminarium/

2. .NET overview

This chapter presents the .NET architecture in a general perspective and serves as an introduction for the reader to the rest of this paper.

2.1 .NET in general

Microsoft Corporation announced its .NET project in July 2001. The .NET project is a massive area of Microsoft's current interests in the computing industry today. It consists of a wide area of separable blocks, forming a new way of thinking in computing and data management of today. .NET brings with it a lot of new tools and techniques, but also incorporates existing techniques. Example of existing techniques that have been allowed to live on in the .NET world is COM/COM+ and ASP. New techniques are, among others, a strong commitment to open standards, such as XML, HTTP and SOAP. A better support for object-oriented programming design and focus on the Internet is also to be found in .NET.

The .NET platform can be separated into four product groups:

1.  Development tools

·  the .NET languages

-  Visual Basic.NET

-  C# ("CSharp")

-  Managed C++

-  J# ("JSharp")

-  IL (Intermediate Language, the .NET bytecode)

·  A set of development tools, mainly Visual Studio.NET and a number of smaller utilities related to this

·  An extensive class library serving as a base for the .NET architecture, namely the .NET Framework

·  CLR, the Common Language Runtime, which executes code built within the framework mentioned above

2.  Server and storage tools

·  A set of specialized application server and storage tools targeting the .NET architecture. These are meant to offer advanced business-to-business, data storage and presentation capabilities with a learning curve that is not steep. These tools will not be covered more deeply in this text, but a listing is provided below.

-  Application Center 2000

-  BizTalk Server 2000

-  Commerce Server 2000

-  Exchange Server 2000

-  Host Integration Server 2000

-  Internet Security and Acceleration Server 2000

-  SQL Server 2000

3.  Web Services

Microsoft (MS) sets out to be the main provider of commercial web services. Developers pay MS an amount of money and are provided with proved MS techniques such as user identification and transaction management. For example Hotmail and the Passport user management technique used extensively at Microsoft's web sites.

4.  Devices

Diverse electronically driven devices, mostly non-PC devices such as terminals, game boxes (X-Box) and cell phones. All these have a .NET-style programmatic interface.

2.2 Microsoft.NET

Microsoft's main idea behind .NET is to enable software to be provided as a service. But .NET is much more than that, MS stays with the following designs and trends within the software industry:

·  Distributed computing

MS has realized that open standards are a key concept in modern information and data management. .NET uses open Internet standards, such as HTTP, XML and SOAP.

·  Componentization

Integration and easy re-use of software components, in the MS world mainly known as COM. But COM component deployment is too complex and error-prone. .NET provides a more logical and a simpler way to build and, especially, deploy software components.

·  Enterprise services

MS provides tools that take care of transaction handling, transaction pooling and security issues. See the list of server tools mentioned earlier. This leaves room for the developers to be able to concentrate on the business logic when building large-scale business systems.

·  Modern and logical use of the Internet

Developing web-based applications has changed form over the years. In the early stages of the Web, focus was on the connectivity layer (TCP/IP), later evolving to the presentation layer (HTML etc.). Nowadays, the focus is on scalability and programmability, made real through communication interfaces such as XML and object communication protocols such as SOAP and Corba.

2.3 The .NET platform

The platform consists of these components:

Figure 2-1 - The .NET platform

The Common Language Specification (CLS), Common Type System (CTS) and the Common Language Runtime (CLR) are meant to enable any language on any platform to be written using the .NET Framework API. You, as the developer, would write code using the Visual Studio.NET Integrated Development Environment (IDE). Code, targeting the CLR and conforming with the rules specified by the CTS and the CLS.

As can be see in Figure 2-1, Perl is mentioned as a valid programming language in the .NET environment. Why is this? Perl is not a programming language with Microsoft's copyright. But, .NET enables Perl code to be executed as a regular Windows Portable Executable (PE) program file. Obviously the Perl code need to be compiled with a compiler targeting the CLR. Such a compiler is not available on the market today, but since the CLS is an open, free-of-charge specification, anybody could write one.

2.4 Language integration and language independence

Programmers and application developers are as people are most, people have opinions and see things differently. What does this mean when doing things such as writing a computer program? It means that there are as many ways of doing it as there are programmers. Software needs to be re-used and updated, but the wheel does not need to be re-invented. This tells us that there is a need for standards and specifications. However, there is also a need for such things as independence for a programmer to use the language he/she knows best. One of the cornerstones of COM is language independence, a COM component can be written in any language, as long as it meets the rules stipulated by the COM specification.

.NET takes this a step further, enabling language integration. One can inherit from classes, throw/catch exceptions and use object-oriented techniques such as polymorphism, across different languages. The main pieces in the .NET architecture enabling this are, the CLR, the CLS, the CTS, and the Common Language Infrastructure (CLI). The CLI is a subset of the CLR. MS has submitted the full CLI specification to the ECMA. (1

1) ECMA is an international industry association founded in 1961 and dedicated to the standardization of information and communication systems.

2.5 Deployment and installation of .NET software

In the Windows world there is such a thing as DLL Hell. This is when an installation program copies a DLL file to the computer, and overwrites an existing DLL with the same name. If these two DLLs are dissimilar in their external interfaces, it might cause an existing application to stop working or to execute incorrectly. This version conflict dilemma has over the years been the most severe problem when developing Windows applications. MS tried to fix this with its release of Windows 2000, using a caching technique which maintains the original DLLs. This works to some extent, but is still not a completely acceptable solution. .NET introduces a new concept, assemblies. This can be referred to Java's technique with JAR files and manifest files containing versioning details. In .NET, a shared DLL must be registered in the Global Assembly Cache (GAC) before use. A (shared) DLL must also have a unique hash value, public key, locale and version number. This ensures that a .NET executable will be executed using the same DLL with which it was built. This is, in my opinion, one of the biggest advantages of the .NET architecture.

3. The .NET Framework

3.1 The .NET Framework architecture

Figure 3-1 - The .NET Framework architecture

The .NET Framework is an Application Programming Interface (API), similar to other standard APIs such as STL, MFC, ATL and Java's API collection.

The section named Base Class Library contains code for basic things such as input-output, string manipulation, security, threading, reflection and collections. This is code which is to be found in every similar collection of code.

On top of this layer is the Data and XML layer. This layer consists of code supporting data management and communication using XML. These classes are extensively used when building client-service applications and when databases are involved.

The topmost layer consists of three distinguishable class hierarchies, extending the first and the second layer. This separation into three blocks is new. Earlier there was not as clear a separation of these as within the .NET Framework This is explained more below.

4. Development using the .NET architecture

This chapter exemplifies the advantages within programming against one API over the old-fashioned way of having one API for every language.

4.1 One language – one API

There are 5-15 different programming languages in frequent use these days. A majority of these have evolved from completely different companies. This means that although the general idea behind every language is more or less the same, there are still many differences. These are mostly related to which programming paradigm serves as a base for the particular language and for what main purpose the language is to be used. Almost every language is shipped with its own collection of low-level code and data structures. This is the API. The API serves as a layer laying on top of the OS and the

compiler/interpreter and beneath the compiled language code.

Figure 4-1 – The Visual Studio 6.0 API architecture

In Visual Studio.NET's predecessor Visual Studio 6.0 a programmer has not much advantage in knowing e.g Visual Basic's API if there is a need to do something in Visual C++. The APIs are different.

Figure 4-2 – One API for every language

Figure 4-2 further illustrates the text in the section above. There is as many APIs as there are languages. There are, of course, not only disadvantages with this. An API can be very specific for some particular task, and enable some miscellaneous programming task to be done smoothly using this particular API. One could, for example, have an API specialized for parallel programming, or an API for programming following some specific specification technique.

Figure 4-3 – One API for all languages

Figure 4-3 illustrates the idea behind the .NET API. All languages can use the same API. Obviously there need to be a language-specific compiler targeting the CLR, as mentioned earlier.

4.2 A few .NET code examples

This section shows the advantages of using the same classes and method names across different .NET languages, over using differing classes and method names in other languages. The well-known "Hello World"-example will be used to demonstrate purposes.

4.2.1 Hello World in Java

Java has an extensive API. It is in my opinion a very good one.

This is how a "Hello World" program would be written in Java.

Figure 4-4 – Hello World in Java

4.2.2 Hello World in C++

C++ is also a very popular language, with a lot of usage areas. I find the syntax to be difficult to read fast and that program development is a lengthy operation in C++.

However, there is no doubt that the fastest running applications are written using C++.

This is how a "Hello World" program would be written in C++.

(compiled using MS Visual C++ 6.0)

Figure 4-5 – Hello World in C++

4.2.3 Hello World in VB.NET

Figure 4-6 – Hello World in VB.NET

In this example VB.NET-application, and in the two following, one and the same class and associated method will be used. Namely the Console class and its WriteLine method. This class belongs to the namespace called System. (Namespaces should be familiar to C++ coders.)

4.2.4 Hello World in C#

Figure 4-7– Hello World in C#

Note that the only thing that differs the C# code from the VB.NET code is the way the code line is marked as finished. (The ";"-sign in C# and the absence of it in VB.NET) Method invoking on objects is also done in the same way, using the "."-notation. (Console.WriteLine)

C#'s syntax is very much a Java-look-a-like. Microsoft has "loaned" the best ideas from Java, added some of their own ideas, and created a powerful object-oriented programming language. A large part of the .NET Framework is written in C#.