Thursday, November 25, 2004

Importance of ClickOnce Deployment

ClickOnce deployment is a deployment technology for smart clients; if you have ever built any smart clients, you will be agreed that as of now , they are built using No-Touch deployment. Though No touch deployment in itself is great but contain few issues that needs to be resolved. Some of those issues with No touch deployment are

1) Smart Client applications cannot check for updates on their deployment server
2) They cannot incrementally update themselves

Let’s think of how to build an auto update feature in No touch deployment. For doing this, a developer needs to write and implement this feature but in ClickOnce, a smart client auto update feature is built into the framework which is responsible for checking for the application updates automatically. Obviously, these are smart client applications written using .NET FX 2.0 to take advantage of ClickOnce but the developer doesn’t write any code for update check or to pull down updates. If an update is detected, it can be pulled down incrementally or in whole by the ClickOnce subsystem it makes the updating of Smart Clients very easy

Tuesday, November 16, 2004

Seminar from Steve Ballmer, CEO Microsoft

On a few days visit to India, Steve Ballmer, CEO of Microsoft spends some time with the developer community of Bangalore. I was honured to get a chance to attended that seminar On a one hour, he had been very clear about the Microsoft Strategies towards .NET and taking some collaboation with Indian companies. Steve Ballmer clearly stated that Microsoft is not looking for developing .NET in platforms other than windows.He clearly stated that .NET is not going to be Platform independent and also laugh when asked about Projects like MONO in Linux. He regarded these as the bad clone of .NET. He showed a great intrest in interoperability and strenghthen the use of Web services and also declared it Microsoft is also looking for some security aspect with it by implementing and enhancing WS-I. On one of the question asked for the qualities to be a CEO, he responded that a person should be Optimist and Good Team leader along with having a Great Sales Representative. He had also given some information about the LongHorn, Yukon and Whidbey as the future products. One of the intresting thing that i got to know in his seminar was about Microsoft Sharepoint Portal Server. On talking about Mobile development, He informed that Microsoft CE.NET will be more enhanced to meet the customer needs. This is the product that has given Microsoft highest revenue till now in the history of Microsoft.

Wednesday, November 10, 2004

Structured Exception Handling of my Life

TRY
{
Trouble Trouble till Termination;
TRY TRY till Totality;
GO,GET,GOING;

}
catch( Negligence)
{
Woods are lovely Dark and Deep;
Miles to Go before i Sleep and Miles to go Before i Sleep;
}
catch
{

Learn the road by travelling it rather than consulting all the maps of world;
}
Finally
{
ARISE, AWAKE AND STOP NOT TILL THE GOAL IS REACHED;

}

Discount on Microsoft exams

Good News Guys,

You can also avail a 20% discount on Microsoft Certification exam fees if you take your exams before December 31, 2004. To learn more about the offer, please visit

http://www.microsoft.com/india/learning/makeyourmove/

Tuesday, November 09, 2004

When to use Exceptions in .NET

Introduction
I had seen a lot of articles and problems on .NET pointing about the need of exception problems. This small article will point of need of the exceptions and its usage.The main importance is to increase capability in right usage of exceptions in .NET and not in how to write exceptions.

Exception , Bugs and Errors ? Three different Enemies

It is a common misconception to know that developers use to think of Errors , bugs and Exceptions as the same acronym but in reality they are different. Lets see it one by one. Bugs generally arises due to programmers mistake and even the compiler are the first friend to fights against this bug by informing about the syntactical accuracies.. Though Bugs can also led to exceptions but can be avoided if we write good code. We should atleast minimize the usage of bugs by writing clear code.

Errors arises due to User's mistake. For example the user has entered the string in case of integer. Though exception can also arise due to errors but one should avoid errors by writing the good validation code. This precaution not only safe us from writing wrong exceptions but do help us in writing good coding.

Exceptions are not necessarily errors
. Whether or not an exception represents an error is determined by the application in which the exception occurred. An exception that is thrown when a file is not found may be considered an error in one scenario, but may not represent an error in another.

You should not use exceptions as a means to provide your intended functionality. For example, a user might enter an invalid user name or password while logging on to an application. While this is not a successful logon, it should be a valid and expected result, and therefore should not throw an exception. However, an exception should be generated if an unexpected condition occurs, such as an unavailable user database. Throwing exceptions is more expensive than simply returning a result to a caller. Therefore they should not be used to control the normal flow of execution through your code. In addition, excessive use of exceptions can create unreadable and unmanageable code.

Exceptions are known but unpreventable errors for eg, out of memory etc... This is the place where your exception handling comes into account and can atleast notify the user with the problem. As a good coding syle, i will always recommend you to write exception handling to deal with only unprevetable situation. Though Microsoft has really put its sincere effort in helping us dealing wiht all kind of exception which either arises due to bugs, errors or exception but you should avoid using exception handling till the time it is not required. One of the reason writing the above statement is that Exception handling is memory intensive and can also affect other application running concurently. Throwing exceptions on things like invalid arguments to an API is probably just fine, but on the other hand throwing an exception due to invalid user input, or badly formatted text from an external system, could be a bad idea. Significant use of exceptions in business logic validation is more often a bad idea than a good one,

It is often preferable to use Multiple Catch statements in a single Try block, although the placement of Catch statements can impact performance.To understand about the exception hierarchy is the formost task and one should give a deep thought before dealing with exceptions in .NET. Once an exception is caught, the processing of the remaining Catch statements is aborted. Subsequently, once the Catch clause completes processing, the Finally clause is processed if available. To make your exception handler more clear, specific and efficient , go from Specific exceptiion to Generic ones.

class ExceptionTestClass
{
public static void Main()
{
int x = 0;
try
{
int y = 100/x;
}
catch (ArithmeticException e)
{
Console.WriteLine("ArithmeticException Handler: {0}", e.ToString());
}
catch (Exception e)
{
Console.WriteLine("Generic Exception Handler: {0}", e.ToString());
}
}
}


See in this example , it is better to catch the Arithmetic exception first and then Exception class as the base exception class is System.Exception.One important thing that should be taken care is that altrhough you should put all the specific handling catch blocks but should also catch any unhandled exception through System.Exception class. See in this example, Is there any neccessity to catch the Arithmetic exception if user would have entered the value of x. In that case, Probably, it would have been checked through validation code . You demanded that user should entered any numeric non zero value, but if user has entered 0, you should checked through your validation code and rather than using the exception.

Finally : Exceptions are like Accidents

You don't know when you can met with an exception so you should have the precautionary measure. This precautionary measure is very important and approriate measure should be taken at appropriate position.For example , In case, if you will wear a helmet while you are in boat does not make sense to all.

Though i had not covered this article by giving some code example but has deal with the situation which can help developers to become judicious in the usage of the Exceptions. I hope this small article would be of great usage to all the developers trying to know where to use the exception handling or not.

Serialization in .NET

Introduction
Serialization is a process of taking an object and converting into a form so that it can be transported across the network or can be persisted in the storage location. This storage location can be physical file, database or ASP.NET Cache. The form contains the state of the object so that by this format, we can construct the same object a later point in time, which is called Deserialization.

There are three formats of serialization

Binary Serialization : Light and compact used in Remoting
SOAP Serialization : interoperable use SOAP and used in web Services
XML Serialization : Custom Serialization



XML SerializationFor XML serialization, you need to use the attributes and specify them for each and every public member that you need. But since it is limited that it can serialize only public members, Serization done by it is called custom serialization. It is also known as Shallow Serialization

SOAP and Binary SerializationXML serializes only public members of the class. You use SOAP or Binary serialization when you need to transport data across the network. SOAP sends it using HTTP Protocol which makes it most interoperable while Binary serialization is known for its light and compact nature. Web Services uses the SOAP Serialization and Remoting uses the Binary Serialization. Infact Serialization is always neccessary when you need the object to transfer across a network. Advantage of using the SOAP or Binary serialization is that you can serialize the entire object and all those object that are being refrenced by it. This is why it is also called Deep Serialization. If you want any class to serialize through any of these methods then you should use [Serializable] attribute on that class and then you can use the SoapFormater class or BinaryFormatter class to do the serialization. These classes have Serialize and DeSerialize method. If you will not use SerializableAttribute for the class, then it will raise the exception.

Though this is the easiest way but at time you need the way so that you can decide what fields to serialize and how the serialization actually occurs. You can implement the ISerializable interface in the class. You need two things for that

Constructor that is overridden and can handle the Deserialization process
GetObject method that tracks about which data is serialized.
A small example below illustrate this all.

public class Employee :ISerializable
{
private int emp_no;
private string name;

protected TestData(SerializationInfo info,StreamingContext context)
{
this.emp_no = info.GetInt32("emp_no");
this.name = info.GetString("name");
}
void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{
info.AddValue("emp_no", this.emp_no);
info.AddValue("name", this.name);
}
}
}


I hope this introductory serialization information can help you to understands about Serialization with its need and its effective usage.