Showing posts with label .Net Frame work. Show all posts
Showing posts with label .Net Frame work. Show all posts

Jan 5, 2015

Programmatically adding break-point in Visual Studio



Many a times, we wish to debug our code based on some condition, we can do this by using code statements in Visual Studio.
There is no need to keep a break-point explicitly, we can use the "Break" method present in `System.Diagnostics.Debugger` class. Here is a short example with console application, but we can do the same for all types of projects built with .Net framework.
 
  1. static void Main(string[] args)
  2. {
  3. Console.WriteLine(2);
  4. int x = 10;
  5. Console.WriteLine(x);
  6. if (x == 10)
  7. System.Diagnostics.Debugger.Break();
  8. Console.WriteLine(1);
 
 
Here, when we run the application in Debug mode, breakpoint will automatically hit the line# 7. Thus, this will be helpful when we wish to debug only when some condition is satisfied.

May 29, 2014

.NET Program Execution

Let us first understand how VB6 or C++ programs (Non Dotnet applications) used to execute. We know that computers only understand machine level code. Machine level code is also called as native or binary code. So, when we execute a VB6 or C++ program, the respective language compiler, compiles the respective language source code into native code, which can then be understood by the underlying operating system and hardware. This process is depicted in the image below.




Native code is specific (native) to the operating system on which it is generated. If you take this compiled native code and try to run on another operating system it will fail. So the problem with this style of program execution is that, it is not portable from one platform to another platform.


Let us now understand, how a .Net program executes. Using dotnet we can create different types of applications. A few of the common types of .NET applications include Web, Windows, Console and Mobile Applications. Irrespective of the type of the application, when you execute any .NET application the following happens


1. The .NET application gets compiled into Intermediate language (IL). IL is also referred as Common Intermediate language (CIL) and Microsoft Intermediate language (MSIL). Both .NET and non .NET applications generate an assembly. Assemblies have an extension of .DLL or .EXE. For example if you compile a windows or Console application, you get a .EXE, where as when we compile a web or Class library project we get a .DLL. The difference between a .NET and NON .NET assembly is that, DOTNET Assembly is in intermediate language format where as NON DOTNET assembly is in native code format.


2. NON DOTNET applications can run directly on top of the operating system, where as DOTNET applications run on top of a virtual environment called as Common Language Runtime (CLR). CLR contains a component called Just In-Time Compiler (JIT), which will convert the Intermediate language into native code which the underlying operating system can understand.

So, in .NET the application execution consists of 2 steps
1. Language compiler, compiles the Source Code into Intermediate Language (IL)
2. JIT compiler in CLR converts, the IL into native code which can then be run on the underlying operating system.


This process is shown in the image below.


  
 Since, a .NET assembly is in Intermedaite Language format and not native code, .NET assemblies are portable to any platform, as long as the target platform has the Common Language Runtime (CLR). The target platform's CLR converts the Intermedaite Language into native code that the underlying operating system can understand. Intermediate Languge is also called as managed code. This is because CLR manages the code that runs inside it. For example, in a VB6 program, the developer is responsible for de-allocating the memory consumed by an object. If a programmer forgets to de-allocate memory, we may run into hard to detecct out of memory exceptions. On the other hand a .NET programmer need not worry about de-allocating the memory consumed by an object. Automatic memory management, also known as grabage collection is provided by CLR. Apart, from garbage collection, there are several other benefits provided by the CLR, which we will discuss in a later session. Since, CLR is managing and executing the Intermediate Language, it (IL) is also called as managed code.

.NET supports different programming languages like C#, VB, J#, and C++. C#, VB, and J# can only generate managed code (IL), where as C++ can generate both managed code (IL) and un-managed code (Native code).
The native code is not stored permanently anywhere, after we close the program the native code is thrown awaya. When we execute the program again, the native code gets generated again.
.NET program is similar to java program execution. In java we have byte codes and JVM (Java Virtual Machine), where as in .NET we Intermediate Language and CLR (Common Language Runtime)

Jul 30, 2012

Difference between .NET 2.0/3.0/3.5 Framework


NET framework 2.0:

It brings a lot of evolution in class of the framework and refactor control including the support of

Generics
Anonymous methods
Partial class
Nullable type
The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading and more
Full 64-bit support for both the x64 and the IA64 hardware platforms
New personalization features for ASP.NET, such as support for themes, skins and webparts.
.NET Micro Framework


NET framework 3.0:
Also called WinFX,includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems and provides

Windows Communication Foundation (WCF), formerly called Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.
Windows Presentation Foundation (WPF), formerly called Avalon; a new user interface subsystem and API based on XML and vector graphics, which uses 3D computer graphics hardware and Direct3D technologies.
Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows.
Windows CardSpace, formerly called InfoCard; a software component which securely stores a person's digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website


.NET framework 3.5:

It implement Linq evolution in language. So we have the folowing evolution in class:

Linq for SQL, XML, Dataset, Object
Addin system
p2p base class
Active directory
ASP.NET Ajax
Anonymous types with static type inference
Paging support for ADO.NET
ADO.NET synchronization API to synchronize local caches and server side datastores
Asynchronous network I/O API
Support for HTTP pipelining and syndication feeds.
New System.CodeDom namespace. 

there were not major changes in .NET version 1.0, 1.1, and 2.0 besides fixing bugs, add new minor features, and better design and tools in Visual Studio 2005. Technologies that were part of .NET 1.0 - 2.0 were Windows Forms, ADO.NET, ASP.NET. 

But major changes came in .NET 3.0 when WPF was introduced. .NET 3.0 was short-lived due to many problems and inconsistencies but version 3.5 came with major fixes and improvements. It runs with Visual Studio 2008 and 2010. In .NET 3.5, besides Windows Forms, ADO.NET, ASP.NET, Web Services, .NET Remoting, we have new technologies including WPF, Silverlight, LINQ, WF, and WCF.

Now we have .NET Framework 4.0. .NET Framework is much improved version of .NET 3.5. 


Dynamic Keyword


After the introduction of "var" in C# 3.5, the use of anonymous types increased rapidly. But as C# doesn't truly supporting the dynamic types, which means the types will be determined during the runtime and any error that is produced will not affect compilation of the project, there were lots of limitations. var is determined during compile time, and it is implicitly typed variable so it cant be a return type of a method. dynamic on the other hand can be a part of return type or argument of a method and will act during runtime when actual object is set to it. 




Apr 12, 2011

Difference between Build Solution and Rebuild Solution option in VS.Net

VisualStudio.Net provides us with two options for compiling and creating builds for our application. They are Build Solution and Rebuild Solution options which can be accessed from the Build menu. The differences between these two options are

Build Solution:


The Build Solution option compiles only those project files and components that have changed since the last build. For example consider that you have two projects Proj1 and Proj2 in your solution MySolution. When you compile the solution using Build Solution option after making some changes to Proj1 only Proj1 will be compiled and built but Proj2 will not be compiled since there are no changes to it.

Rebuild Solution:


 On the other hand the Rebuild Solution option builds all project files and components irrespective of the changes made to them.  For example consider that you have two projects Proj1 and Proj2 in your solution MySolution. When you compile the solution using Rebuild Solution option after making some changes to Proj1, both Proj1 and Proj2 will be compiled and built even though there are no changes made to Proj2.

Jul 5, 2010

Difference between var type of .NET 3.5 and object Data Type in .NET 2.0

With .NET 3.5 a new feature is introduced of defining Anonymous Type.
You can achieve this with keyword "var".

We can achieve the same functionality in .NET 2.0 with object type.

What is the difference between var type of .NET 3.5 and object Data Type in .NET 2.0?

var types are actually strongly typed in design time. What happens in the IDE infers the type of the object based on its initialisation so you get strong typing and intellisense
e.g.
var i = 99;
the IDE will pick up the i is an integer
using object you lose strong typing as all objects and primitive types inherit from object so you can potentially get runtime errors and type casting will give you a performance hit.



How var is strong type? The Value is assigned to var Variable at run time.

var is not assigned at runtime but design time that is why it is strongly typed.
Its type is inferred by the value that is initialised. That is why when you use VAR you need to declare and assign it in the one line

Another point is the difference of type casting. In object I have to type Cast explicitly and in case of var it's not required. is this correct?


You do not need to cast the VAR because it is strongly typed unlike object

Introduction to var datatype in C#

Var Type: 

  • C# 3.0 adds the interesting behavior of Declaring Local Variables Implicitly. This means that there is no need to mention the  data type when declaring a variable. A local variable can be declared implicitly using the var keyword in C#.
  • Declaring local variables implicitly has some restrictions; the variable must be initialized to some expression that can not be null.

    var a= 10;
    var z = "Rekha";
  • The primary reason for its existence is the introduction of anonymous types in C#
  • Another point to stress is that variable inference does not work for class level fields or method arguments or anywhere else other than for local variables in a method.
Advantages :
  • Less typing with no loss of functionality
  • Increases the type safety of your code. A foreach loop using an iteration variable which is typed to var will catch silently casts that are introduced with explicit types
  • Makes it so you don't have to write the same name twice in a variable declaration.
  • Some features, such as declaring a strongly typed anonymous type local variable, require the use of var
Example 1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Namesp1{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Convert.ToInt32(Console.ReadLine());
            var y = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("The Sum Is : " + (x + y));         }
    }
}

Example 2:
 
using
System;
namespace ConsoleApplication1
{
    class A
    {
        public static void Main()
        {
            int sum = 0;
            int[] arr = new int[10];
            for (int i = 0; i < 10; i++)
            {
                arr[i] = i;
            }
            foreach (var x in arr)
            {
                Console.WriteLine("Value is: " + x);
                sum =sum + x;
            }
            Console.WriteLine("Sum of array elements is : " + sum);
        }
    }
}
Output:
VarOutput.bmp

May 5, 2010

What is Microsoft .NET?

Microsoft .NET (pronounced “dot net”) is a software component that runs on the Windows operating system. .NET provides tools and libraries that enable developers to create Windows software much faster and easier. .NET benefits end-users by providing applications of higher capability, quality and security. The .NET Framework must be installed on a user’s PC to run .NET applications.


This is how Microsoft describes it: “.NET is the Microsoft Web services strategy to connect information, people, systems, and devices through software. Integrated across the Microsoft platform, .NET technology provides the ability to quickly build, deploy, manage, and use connected, security-enhanced solutions with Web services. .NET-connected solutions enable businesses to integrate their systems more rapidly and in a more agile manner and help them realize the promise of information anytime, anywhere, on any device.” 


What is the .NET architecture?

Microsoft .NET consists of four major components:
  • Common Language Specification (CLS) – blue in the diagram below
  • Framework Class Library (FCL) – red
  • Common Language Runtime (CLR) – green
  • .NET Tools – yellow



At the base of the diagram in gray is the operating system, which technically can be any platform but typically is Microsoft Windows 2000 or greater, accessed through the Win32 API (Application Programming Interface).


Common Language Specification (CLS)

The CLS is a common platform that integrates code and components from multiple .NET programming languages. In other words, a .NET application can be written in multiple programming languages with no extra work by the developer (though converting code between languages can be tricky).
.NET includes new object-oriented programming languages such as C#, Visual Basic .NET, J# (a Java clone) and Managed C++. These languages, plus other experimental languages like F#, all compile to the Common Language Specification and can work together in the same application.


Framework Class Library (FCL)

The FCL is a collection of over 7000 classes and data types that enable .NET applications to read and write files, access databases, process XML, display a graphical user interface, draw graphics, use Web services, etc. The FCL wraps much of the massive, complex Win32 API into more simple .NET objects that can be used by C# and other .NET programming languages.


Common Language Runtime (CLR)

The CLR is the execution engine for .NET applications and serves as the interface between .NET applications and the operating system. The CLR provides many services such as:
  • Loads and executes code
  • Converts intermediate language to native machine code
  • Separates processes and memory
  • Manages memory and objects
  • Enforces code and access security
  • Handles exceptions
  • Interfaces between managed code, COM objects, and DLLs
  • Provides type-checking
  • Provides code meta data (Reflection)
  • Provides profiling, debugging, etc.


.NET Tools

Visual Studio .NET is Microsoft’s flagship tool for developing Windows software. Visual Studio provides an integrated development environment (IDE) for developers to create standalone Windows applications, interactive Web sites, Web applications, and Web services running on any platform that supports .NET.
In addition, there are many .NET Framework tools designed to help developers create, configure, deploy, manage and secure .NET applications and components.


What is the history of .NET?

.NET started as a classic Microsoft FUD operation. In the late 1990s, Microsoft had just successfully fought off a frontal assault on its market dominance by killing the Netscape Web browser with its free Internet Explorer. But Microsoft was facing a host of new challenges, including serious problems with COM, C++, DLL hell, the Web as a platform, security, and strong competition from Java, which was emerging as the go-to language for Web development.

Microsoft started building .NET in the late 90s under the name “Next Generation Windows Services” (NGWS). Bill Gates described .NET as Microsoft’s answer to the “Phase 3 Internet environment, where the Internet becomes a platform in its own right, much like the PC has traditionally been… Instead of a world where Internet users are limited to reading information, largely one screen at a time, the Phase 3 Internet will unite multiple Web sites running on any device, and allow users to read, write and annotate them via speech, handwriting recognition and the like,” Gates said. We are certainly approaching that vision.


Microsoft announced .NET to the world in June 2000 and released version 1.0 of the .NET framework in January 2002. Microsoft also labeled everything .NET including briefly Office to demonstrate its commitment and dominance on this new thing called the Web. But out of that grand FUD campaign emerged the very capable and useful .NET development environment and framework for both the Web and Windows desktop.

What are the benefits of .NET?

.NET provides the best platform available today for delivering Windows software. .NET helps make software better, faster, cheaper, and more secure. .NET is not the only solution for developing Web software—Java on Linux is a serious alternative. But on the Windows desktop, .NET rules.


For developers, .NET provides an integrated set of tools for building Web software and services and Windows desktop applications. .NET supports multiple programming languages and Service Oriented Architectures (SOA).


For companies, .NET provides a stable, scalable and secure environment for software development. .NET can lower costs by speeding development and connecting systems, increase sales by giving employees access to the tools and information they need, and connect your business to customers, suppliers and partners.
For end-users, .NET results in software that’s more reliable and secure and works on multiple devices including laptops, Smartphones and Pocket PCs.


Which versions of .NET are available?

The newest version available today is NET v3.0, but most PC users have v2.0 installed.
Although .NET v3.0 is now available, Windows Update is not automatically installing it, hence few people have it. People who purchase new PCs with Windows Vista pre-installed will receive the latest .NET v3.0 but there may be some versioning issues. Microsoft released a beta version of .NET v3.5 in April 2007.
Following are the production versions of .NET:


Version Name Version Number Release Date
1.0 1.0.3705.0 2002-01-05
1.0 SP1 1.0.3705.209 2002-03-19
1.0 SP2 1.0.3705.288 2002-08-07
1.0 SP3 1.0.3705.6018 2004-08-31
1.1 1.1.4322.573 2003-04-01
1.1 SP1 1.1.4322.2032 2004-08-30
2.0 2.0.50727.42 2005-11-07
3.0 3.0.4506.30 2006-11-06