<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8699050161859053643</id><updated>2011-11-27T15:40:32.589-08:00</updated><title type='text'>Dot Net Library</title><subtitle type='html'>All about .NET....</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-5091829033281611242</id><published>2008-07-01T04:23:00.000-07:00</published><updated>2008-12-09T16:00:13.768-08:00</updated><title type='text'>.NET Interview Faq</title><content type='html'>&lt;strong&gt;.NET Framework - FAQ&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When was .NET announced?&lt;/strong&gt;&lt;br /&gt;Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and delegates were given CDs containing a pre-release version of the .NET framework/SDK and Visual Studio.NET. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When was the first version of .NET released?&lt;/strong&gt;&lt;br /&gt;The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time, the final version of Visual Studio.NET was made available to MSDN subscribers.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What platforms does the .NET Framework run on?&lt;/strong&gt;&lt;br /&gt;The runtime supports Windows XP, Windows 2000, NT4 SP6a and Windows ME/98. Windows 95 is not supported. Some parts of the framework do not work on all platforms - for example, ASP.NET is only supported on Windows XP and Windows 2000. Windows 98/ME cannot be used for development.&lt;br /&gt;&lt;br /&gt;IIS is not supported on Windows XP Home Edition, and so cannot be used to host ASP.NET. However, the ASP.NET Web Matrix web server does run on XP Home.&lt;br /&gt;The Mono project is attempting to implement the .NET framework on Linux. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the CLR?&lt;/strong&gt;&lt;br /&gt;CLR = Common Language Runtime. The CLR is a set of standard resources that (in theory) any .NET program can take advantage of, regardless of programming language. Robert Schmidt (Microsoft) lists the following CLR resources in his MSDN PDC# article:&lt;br /&gt;&lt;br /&gt;Object-oriented programming model (inheritance, polymorphism, exception handling, garbage collection) &lt;br /&gt; Security model &lt;br /&gt; Type system &lt;br /&gt; All .NET base classes &lt;br /&gt; Many .NET framework classes &lt;br /&gt; Development, debugging, and profiling tools &lt;br /&gt; Execution and code management &lt;br /&gt; IL-to-native translators and optimizers &lt;br /&gt;&lt;br /&gt;What this means is that in the .NET world, different programming languages will be more equal in capability than they have ever been before, although clearly not all languages will support all CLR services.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What is the CTS?&lt;/strong&gt;&lt;br /&gt;CTS = Common Type System. This is the range of types that the .NET runtime understands, and therefore that .NET applications can use. However note that not all .NET languages will support all the types in the CTS. The CTS is a superset of the CLS. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the CLS?&lt;/strong&gt;&lt;br /&gt;CLS = Common Language Specification. This is a subset of the CTS which all .NET languages are expected to support. The idea is that any program, which uses CLS-compliant types, can interoperate with any .NET program written in any language.&lt;br /&gt;In theory this allows very tight interop between different .NET languages - for example allowing a C# class to inherit from a VB class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is IL?&lt;/strong&gt;&lt;br /&gt;IL = Intermediate Language. Also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code (of any language) is compiled to IL. The IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does 'managed' mean in the .NET context?&lt;/strong&gt;&lt;br /&gt;The term 'managed' is the cause of much confusion. It is used in various places within .NET, meaning slightly different things.Managed code: The .NET framework provides several core run-time services to the programs that run within it - for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. Such code is called managed code. All C# and Visual Basic.NET code is managed by default. VS7 C++ code is not managed by default, but the compiler can produce managed code by specifying a command-line switch (/com+).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Managed data:&lt;/strong&gt; This is data that is allocated and de-allocated by the .NET runtime's garbage collector. C# and VB.NET data is always managed. VS7 C++ data is unmanaged by default, even when using the /com+ switch, but it can be marked as managed using the __gc keyword.Managed classes: This is usually referred to in the context of Managed Extensions (ME) for C++. When using ME C++, a class can be marked with the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector, but it also means more than that. The class becomes a fully paid-up member of the .NET community with the benefits and restrictions that brings. An example of a benefit is proper interop with classes written in other languages - for example, a managed C++ class can inherit from a VB class. An example of a restriction is that a managed class can only inherit from one base class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is reflection?&lt;/strong&gt;&lt;br /&gt;All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly. &lt;br /&gt;&lt;br /&gt;Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for marshaling data across context/process/machine boundaries.&lt;br /&gt;Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember ) ,  or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between Finalize and Dispose (Garbage collection) ?&lt;/strong&gt;&lt;br /&gt;Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected Finalize Method on an object (destructor syntax in C# and the Managed Extensions for C++). The garbage collector calls this method at some point after there are no longer any valid references to the object. In some cases, you might want to provide programmers using an object with the ability to explicitly release these external resources before the garbage collector frees the object. If an external resource is scarce or expensive, better performance can be achieved if the programmer explicitly releases resources when they are no longer being used. To provide explicit control, implement the Dispose method provided by the IDisposable Interface. The consumer of the object should call this method when it is done using the object. &lt;br /&gt;&lt;br /&gt;Dispose can be called even if other references to the object are alive. Note that even when you provide explicit control by way of Dispose, you should provide implicit cleanup using the Finalize method. Finalize provides a backup to prevent resources from permanently leaking if the programmer fails to call Dispose. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Partial Assembly References?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Full Assembly reference:&lt;/strong&gt; A full assembly reference includes the assembly's text name, version, culture, and public key token (if the assembly has a strong name). A full assembly reference is required if you reference any assembly that is part of the common language runtime or any assembly located in the global assembly cache.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Partial Assembly reference:&lt;/strong&gt; We can dynamically reference an assembly by providing only partial information, such as specifying only the assembly name. When you specify a partial assembly reference, the runtime looks for the assembly only in the application &lt;br /&gt;directory.&lt;br /&gt;&lt;br /&gt;We can make partial references to an assembly in your code one of the following ways:&lt;br /&gt;&lt;br /&gt;-&gt; Use a method such as System.Reflection.Assembly.Load and specify only a partial reference. The runtime checks for the assembly in the application directory.&lt;br /&gt;&lt;br /&gt;-&gt; Use the System.Reflection.Assembly.LoadWithPartialName method and specify only a partial reference. The runtime checks for the assembly in the application directory and in the global assembly cache &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Changes to which portion of version number indicates an incompatible change?&lt;/strong&gt;&lt;br /&gt;Major or minor. Changes to the major or minor portion of the version number indicate an incompatible change. Under this convention then, version 2.0.0.0 would be considered incompatible with version 1.0.0.0. Examples of an incompatible change would be a change to the types of some method parameters or the removal of a type or method altogether. Build. The Build number is typically used to distinguish between daily builds or smaller compatible releases. Revision. Changes to the revision number are typically reserved for an incremental build needed to fix a particular bug. You'll sometimes hear this referred to as the "emergency bug fix" number in that the revision is what is often changed when a fix to a specific bug is shipped to a customer. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is side-by-side execution? Can two application one using private assembly and other using Shared assembly be stated as a side-by-side executables?&lt;/strong&gt;&lt;br /&gt;Side-by-side execution is the ability to run multiple versions of an application or component on the same computer. You can have multiple versions of the common language runtime, and multiple versions of applications and components that use a version of the runtime, on the same computer at the same time. Since versioning is only applied to shared assemblies, and not to private assemblies, two application one using private assembly and one using shared assembly cannot be stated as side-by-side executables. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why string are called Immutable data Type ?&lt;/strong&gt;&lt;br /&gt;The memory representation of string is an Array of Characters, So on re-assigning the new array of Char is formed &amp; the start address is changed . Thus keeping the Old string in Memory for Garbage Collector to be disposed. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does assert() method do?&lt;/strong&gt;&lt;br /&gt;In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between the Debug class and Trace class?&lt;/strong&gt;&lt;br /&gt;Documentation looks the same.  Use Debug class for debug builds, use Trace class for both debug and release builds. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why are there five tracing levels in System.Diagnostics.TraceSwitcher?&lt;/strong&gt;&lt;br /&gt;The tracing dumps can be quite verbose.  For applications that are constantly running you run the risk of overloading the machine and the hard drive.  Five levels range from None to Verbose, allowing you to fine-tune the tracing activities. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Where is the output of TextWriterTraceListener redirected?&lt;/strong&gt;&lt;br /&gt;To the Console or a text file depending on the parameter passed to the constructor. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do assemblies find each other?&lt;/strong&gt;&lt;br /&gt;By searching directory paths. There are several factors which can affect the path (such as the AppDomain host, and application configuration files), but for private assemblies the search path is normally the application's directory and its sub-directories. For shared assemblies, the search path is normally same as the private assembly path plus the shared assembly cache. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How does assembly versioning work?&lt;/strong&gt;&lt;br /&gt;Each assembly has a version number called the compatibility version. Also each reference to an assembly (from another assembly) includes both the name and version of the referenced assembly.The version number has four numeric parts (e.g. 5.5.2.33). Assemblies with either of the first two parts different are normally viewed as incompatible. If the first two parts are the same, but the third is different, the assemblies are deemed as 'maybe compatible'. If only the fourth part is different, the assemblies are deemed compatible. However, this is just the default guideline - it is the version policy that decides to what extent these rules are enforced. The version policy can be specified via the application configuration file. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is garbage collection?&lt;/strong&gt;&lt;br /&gt;Garbage collection is a system whereby a run-time component takes responsibility for managing the lifetime of objects and the heap memory that they occupy. This concept is not new to .NET - Java and many other languages/runtimes have used garbage collection for some time. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why doesn't the .NET runtime offer deterministic destruction?&lt;/strong&gt;&lt;br /&gt;Because of the garbage collection algorithm. The .NET garbage collector works by periodically running through a list of all the objects that are currently being referenced by an application. All the objects that it doesn't find during this search are ready to be destroyed and the memory reclaimed. The implication of this algorithm is that the runtime doesn't get notified immediately when the final reference on an object goes away - it only finds out during the next sweep of the heap.&lt;br /&gt;&lt;br /&gt;Futhermore, this type of algorithm works best by performing the garbage collection sweep as rarely as possible. Normally heap exhaustion is the trigger for a collection sweep. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is the lack of deterministic destruction in .NET a problem?&lt;/strong&gt;&lt;br /&gt;It's certainly an issue that affects component design. If you have objects that maintain expensive or scarce resources (e.g. database locks), you need to provide some way for the client to tell the object to release the resource when it is done. Microsoft recommend that you provide a method called Dispose() for this purpose. However, this causes problems for distributed objects - in a distributed system who calls the Dispose() method? Some form of reference-counting or ownership-management mechanism is needed to handle distributed objects - unfortunately the runtime offers no help with this.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is serialization?&lt;/strong&gt;&lt;br /&gt;Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization / Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Does the .NET Framework have in-built support for serialization?&lt;/strong&gt;&lt;br /&gt;There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can I customise the serialization process?&lt;/strong&gt;&lt;br /&gt;Yes. XmlSerializer supports a range of attributes that can be used to configure serialization for a particular class. For example, a field or property can be marked with the [XmlIgnore] attribute to exclude it from serialization. Another example is the [XmlElement] attribute, which can be used to specify the XML element name to be used for a particular property or field.&lt;br /&gt;&lt;br /&gt;Serialization via SoapFormatter/BinaryFormatter can also be controlled to some extent by attributes. For example, the [NonSerialized] attribute is the equivalent of XmlSerializer's [XmlIgnore] attribute. Ultimate control of the serialization process can be acheived by implementing the the ISerializable interface on the class whose instances are to be serialized. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why is XmlSerializer so slow?&lt;/strong&gt;&lt;br /&gt;There is a once-per-process-per-type overhead with XmlSerializer. So the first time you serialize or deserialize an object of a given type in an application, there is a significant delay. This normally doesn't matter, but it may mean, for example, that XmlSerializer is a poor choice for loading configuration settings during startup of a GUI application. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why do I get errors when I try to serialize a Hashtable?&lt;/strong&gt;&lt;br /&gt;XmlSerializer will refuse to serialize instances of any class that implements IDictionary, e.g. Hashtable. SoapFormatter and BinaryFormatter do not have this restriction.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are attributes?&lt;/strong&gt;&lt;br /&gt;There are at least two types of .NET attribute. The first type I will refer to as a metadata attribute - it allows some data to be attached to a class or method. This data becomes part of the metadata for the class, and (like other class metadata) can be accessed via reflection. &lt;br /&gt;The other type of attribute is a context attribute. Context attributes use a similar syntax to metadata attributes but they are fundamentally different. Context attributes provide an interception mechanism whereby instance activation and method calls can be pre- and/or post-processed.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How does CAS work?&lt;/strong&gt;&lt;br /&gt;The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group, and each code group is granted the permissions specified in a named permission set.&lt;br /&gt;For example, using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group, which adheres to the permissions defined by the 'Internet' named permission set. (Naturally the 'Internet' named permission set represents a very restrictive range of permissions.)  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Who defines the CAS code groups?&lt;/strong&gt;&lt;br /&gt;Microsoft defines some default ones, but you can modify these and even create your own. To see the code groups defined on your system, run 'caspol -lg' from the command-line. On my system it looks like this:&lt;br /&gt;&lt;br /&gt;Level = Machine&lt;br /&gt;Code Groups:&lt;br /&gt;1.  All code: Nothing&lt;br /&gt;   1.1.  Zone - MyComputer: FullTrust&lt;br /&gt;      1.1.1.  Honor SkipVerification requests: SkipVerification&lt;br /&gt;   1.2.  Zone - Intranet: LocalIntranet&lt;br /&gt;   1.3.  Zone - Internet: Internet&lt;br /&gt;   1.4.  Zone - Untrusted: Nothing&lt;br /&gt;   1.5.  Zone - Trusted: Internet&lt;br /&gt;   1.6.  StrongName - 0024000004800000940000000602000000240000525341310004000003&lt;br /&gt;000000CFCB3291AA715FE99D40D49040336F9056D7886FED46775BC7BB5430BA4444FEF8348EBD06&lt;br /&gt;F962F39776AE4DC3B7B04A7FE6F49F25F740423EBF2C0B89698D8D08AC48D69CED0FC8F83B465E08&lt;br /&gt;07AC11EC1DCC7D054E807A43336DDE408A5393A48556123272CEEEE72F1660B71927D38561AABF5C&lt;br /&gt;AC1DF1734633C602F8F2D5: &lt;br /&gt;&lt;br /&gt;Note the hierarchy of code groups - the top of the hierarchy is the most general ('All code'), which is then sub-divided into several groups, each of which in turn can be sub-divided. Also note that (somewhat counter-intuitively) a sub-group can be associated with a more permissive permission set than its parent. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I define my own code group?&lt;/strong&gt;&lt;br /&gt;Use caspol. For example, suppose you trust code from www.mydomain.com and you want it have full access to your system, but you want to keep the default restrictions for all other internet sites. To achieve this, you would add a new code group as a sub-group of the  'Zone - Internet' group, like this: &lt;br /&gt;caspol -ag 1.3 -site www.mydomain.com FullTrust &lt;br /&gt;Now if you run caspol -lg you will see that the new group has been added as group 1.3.1:&lt;br /&gt; &lt;br /&gt;   1.3.  Zone - Internet: Internet&lt;br /&gt;      1.3.1.  Site - www.mydomain.com: FullTrust&lt;br /&gt; &lt;br /&gt;Note that the numeric label (1.3.1) is just a caspol invention to make the code groups easy to manipulate from the command-line. The underlying runtime never sees it. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I change the permission set for a code group?&lt;/strong&gt;&lt;br /&gt;Use caspol. If you are the machine administrator, you can operate at the 'machine' level - which means not only that the changes you make become the default for the machine, but also that users cannot change the permissions to be more permissive. If you are a normal (non-admin) user you can still modify the permissions, but only to make them more restrictive. For example, to allow intranet code to do what it likes you might do this: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;caspol -cg 1.2 FullTrust&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Note that because this is more permissive than the default policy (on a standard system), you should only do this at the machine level - doing it at the user level will have no effect. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;I can't be bothered with all this CAS stuff. Can I turn it off?&lt;/strong&gt;&lt;br /&gt;Yes, as long as you are an administrator. Just run: &lt;strong&gt;caspol -s off &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can I look at the IL for an assembly?&lt;/strong&gt;&lt;br /&gt;Yes. MS supply a tool called Ildasm which can be used to view the metadata and IL for an assembly. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can source code be reverse-engineered from IL?&lt;/strong&gt;&lt;br /&gt;Yes, it is often relatively straightforward to regenerate high-level source (e.g. C#) from IL. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How can I stop my code being reverse-engineered from IL?&lt;/strong&gt;&lt;br /&gt;There is currently no simple way to stop code being reverse-engineered from IL. In future it is likely that IL obfuscation tools will become available, either from MS or from third parties. These tools work by 'optimising' the IL in such a way that reverse-engineering becomes much more difficult.&lt;br /&gt;&lt;br /&gt;Of course if you are writing web services then reverse-engineering is not a problem as clients do not have access to your IL. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is there built-in support for tracing/logging?&lt;/strong&gt;&lt;br /&gt;Yes, in the System.Diagnostics namespace. There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can I redirect tracing to a file?&lt;/strong&gt;&lt;br /&gt;Yes. The Debug and Trace classes both have a Listeners property, which is a collection of sinks that receive the tracing that you send via Debug.WriteLine and Trace.WriteLine respectively. By default the Listeners collection contains a single sink, which is an instance of the DefaultTraceListener class. This sends output to the Win32 OutputDebugString() function and also the System.Diagnostics.Debugger.Log() method. This is useful when debugging, but if you're trying to trace a problem at a customer site, redirecting the output to a file is more appropriate. Fortunately, the TextWriterTraceListener class is provided for this purpose. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the contents of assembly?&lt;/strong&gt;&lt;br /&gt;In general, a static assembly can consist of four elements: &lt;br /&gt;i)   The assembly manifest, which contains assembly metadata. &lt;br /&gt;ii)  Type metadata. &lt;br /&gt;iii) Microsoft intermediate language (MSIL) code that implements the types. &lt;br /&gt;iv)  A set of resources.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is GC (Garbage Collection) and how it works&lt;/strong&gt;&lt;br /&gt;One of the good features of the CLR is Garbage Collection, which runs in the background collecting unused object references, freeing us from having to ensure we always destroy them. In reality the time difference between you releasing the object instance and it being garbage collected is likely to be very small, since the GC is always running.&lt;br /&gt;[The process of transitively tracing through all pointers to actively used objects in order to locate all objects that can be referenced, and then arranging to reuse any heap memory that was not found during this trace. The common language runtime garbage collector also compacts the memory that is in use to reduce the working space needed for the heap.]&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Heap:&lt;/strong&gt;&lt;br /&gt;A portion of memory reserved for a program to use for the temporary storage of data structures whose existence or size cannot be determined until the program is running. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Differnce between Managed code and unmanaged code ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Managed Code:&lt;/strong&gt;&lt;br /&gt;Code that runs under a "contract of cooperation" with the common language runtime. Managed code must supply the metadata necessary for the runtime to provide services such as memory management, cross-language integration, code access security, and &lt;br /&gt;automatic lifetime control of objects. All code based on Microsoft intermediate language (MSIL) executes as managed code. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Un-Managed Code:&lt;/strong&gt;&lt;br /&gt;Code that is created without regard for the conventions and requirements of the common language runtime. Unmanaged code executes in the common language runtime environment with minimal services (for example, no garbage collection, limited debugging, and so on). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is MSIL, IL, CTS and, CLR ?&lt;/strong&gt; &lt;br /&gt;&lt;strong&gt;MSIL: (Microsoft intermediate language)&lt;/strong&gt;&lt;br /&gt;When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be executed, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and executed on any supported architecture.&lt;br /&gt;When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type's members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and Common Object File Format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;IL: (Intermediate Language)&lt;/strong&gt;&lt;br /&gt;A language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;CTS: (Common Type System)&lt;/strong&gt;&lt;br /&gt;The specification that determines how the common language runtime defines, uses, and manages types&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;CLR: (Common Language Runtime)&lt;/strong&gt;&lt;br /&gt;The engine at the core of managed code execution. The runtime supplies managed code with services such as cross-language integration, code access security, object lifetime management, and debugging and profiling support.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Reference type and value type ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Reference Type:&lt;/strong&gt;&lt;br /&gt;Reference types are allocated on the managed CLR heap, just like object types.&lt;br /&gt;A data type that is stored as a reference to the value's location. The value of a reference type is the location of the sequence of bits that represent the type's data. Reference types can be self-describing types, pointer types, or interface types&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Value Type:&lt;/strong&gt;&lt;br /&gt;Value types are allocated on the stack just like primitive types in VBScript, VB6 and C/C++. Value types are not instantiated using new go out of scope when the function they are defined within returns.&lt;br /&gt;Value types in the CLR are defined as types that derive from system.valueType.&lt;br /&gt; &lt;br /&gt;A data type that fully describes a value by specifying the sequence of bits that constitutes the value's representation. Type information for a value type instance is not stored with the instance at run time, but it is available in metadata. Value type instances can be treated as objects using boxing. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Boxing and unboxing ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Boxing:&lt;/strong&gt;&lt;br /&gt;The conversion of a value type instance to an object, which implies that the instance will carry full type information at run time and will be allocated in the heap. The Microsoft intermediate language (MSIL) instruction set's box instruction converts a value type to an object by making a copy of the value type and embedding it in a newly allocated object.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Un-Boxing:&lt;/strong&gt;&lt;br /&gt;The conversion of an object instance to a value type. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is JIT and how is works ?&lt;/strong&gt;&lt;br /&gt;An acronym for "just-in-time," a phrase that describes an action that is taken only when it becomes necessary, such as just-in-time compilation or just-in-time object activation &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is portable executable (PE) ?&lt;/strong&gt;&lt;br /&gt;The file format used for executable programs and for files to be linked together to form executable programs &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is strong name?&lt;/strong&gt;&lt;br /&gt;A name that consists of an assembly's identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly. Because the assembly manifest contains file hashes for all the files that constitute the assembly implementation, it is sufficient to generate the digital signature over just the one file in the assembly that contains the assembly manifest. Assemblies with the same strong name are expected to be identical &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is global assembly cache?&lt;/strong&gt;&lt;br /&gt;A machine-wide code cache that stores assemblies specifically installed to be shared by many applications on the computer. Applications deployed in the global assembly cache must have a strong name. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is difference between constants, readonly and, static ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Constants:&lt;/strong&gt; The value can’t be changed &lt;br /&gt;&lt;strong&gt;Read-only:&lt;/strong&gt; The value will be initialized only once from the constructor of the class.&lt;br /&gt;&lt;strong&gt;Static:&lt;/strong&gt; Value can be initialized once. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is difference between shared and public?&lt;/strong&gt;&lt;br /&gt;An assembly that can be referenced by more than one application. An assembly must be explicitly built to be shared by giving it a cryptographically strong name. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is namespace used for loading assemblies at run time and name the methods?&lt;/strong&gt;&lt;br /&gt;System.Reflection &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the types of authentication in .net?&lt;/strong&gt;&lt;br /&gt;We have three types of authentication: &lt;br /&gt;1. Form authentication &lt;br /&gt;2. Windows authentication&lt;br /&gt;3. Passport&lt;br /&gt;This has to be declared in web.config file. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between a Struct and a Class ?&lt;/strong&gt;&lt;br /&gt;The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects,you will allocate additional memory for referencing each object. In this case, the struct is less expensive.&lt;br /&gt;&lt;br /&gt;When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values.&lt;br /&gt;It is an error to initialize an instance field in a struct.&lt;br /&gt;There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do.&lt;br /&gt;A struct is a value type, while a class is a reference type.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How big is the datatype int in .NET? &lt;/strong&gt;&lt;br /&gt;32 bits.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How big is the char? &lt;/strong&gt;&lt;br /&gt;16 bits (Unicode).  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you initiate a string without escaping each backslash? &lt;/strong&gt;&lt;br /&gt;Put an @ sign in front of the double-quoted string.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the access level of the visibility type internal? &lt;/strong&gt;&lt;br /&gt;Current application.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explain encapsulation?&lt;/strong&gt;&lt;br /&gt;The implementation is hidden, the interface is exposed.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What data type should you use if you want an 8-bit value that's signed? &lt;/strong&gt;&lt;br /&gt;sbyte.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Speaking of Boolean data types, what's different between C# and C/C++? &lt;/strong&gt;&lt;br /&gt;There's no conversion between 0 and false, as well as any other number and true, like in C/C++.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Where are the value-type variables allocated in the computer RAM? &lt;/strong&gt;&lt;br /&gt;Stack.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Where do the reference-type variables go in the RAM? &lt;/strong&gt;&lt;br /&gt;The references go on the stack, while the objects themselves go on the heap.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between the value-type variables and reference-type variables in terms of garbage collection? &lt;/strong&gt;&lt;br /&gt;The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, GC picks up the reference-type objects when their references go null. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you convert a string into an integer in .NET?&lt;/strong&gt;&lt;br /&gt;Int32.Parse(string) &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you box a primitive data type variable? &lt;/strong&gt;&lt;br /&gt;Assign it to the object, pass an object. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why do you need to box a primitive variable?&lt;/strong&gt;&lt;br /&gt;Pass it by reference. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between Java and .NET garbage collectors? &lt;/strong&gt;&lt;br /&gt;Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE you're using. Microsoft standardized on their garbage collection. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you enforce garbage collection in .NET?&lt;/strong&gt;&lt;br /&gt;System.GC.Collect(); &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's different about namespace declaration when comparing that to package declaration in Java? &lt;/strong&gt;&lt;br /&gt;No semicolon.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between const and readonly? &lt;/strong&gt;&lt;br /&gt;You can initialize readonly variables to some runtime values. Let's say your program uses current date and time as one of the values that won't change. This way you declare public readonly string DateT = new DateTime().ToString().  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What happens when you encounter a continue statement inside the for loop? &lt;/strong&gt;&lt;br /&gt;The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the advantage of using System.Text.StringBuilder over System.String? &lt;/strong&gt;&lt;br /&gt;StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you store multiple data types in System.Array? &lt;/strong&gt;&lt;br /&gt;No.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between the System.Array.CopyTo() and System.Array.Clone()? &lt;/strong&gt;&lt;br /&gt;The first one performs a deep copy of the array, the second one performs a shallow copy.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How can you sort the elements of the array in descending order? &lt;/strong&gt;&lt;br /&gt;By calling Sort() and then Reverse() methods.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the .NET datatype that allows the retrieval of data by a unique key?&lt;/strong&gt;&lt;br /&gt;HashTable.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's class SortedList underneath? &lt;/strong&gt;&lt;br /&gt;A sorted Hash Table.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Will finally block get executed if the exception had not occurred? &lt;/strong&gt;&lt;br /&gt;Yes.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can multiple catch blocks be executed?&lt;/strong&gt;&lt;br /&gt;No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why is it a bad idea to throw your own exceptions? Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? &lt;/strong&gt;&lt;br /&gt;Throwing your own exceptions signifies some design flaws in the project.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's a delegate? &lt;/strong&gt;&lt;br /&gt;A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's a multicast delegate? &lt;/strong&gt;&lt;br /&gt;It's a delegate that points to and eventually fires off several methods.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How's the DLL Hell problem solved in .NET? &lt;/strong&gt;&lt;br /&gt;Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32),  but also the version of the assembly.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the ways to deploy an assembly?&lt;/strong&gt;&lt;br /&gt; An MSI installer, a CAB archive, and XCOPY command.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's a satellite assembly? &lt;/strong&gt;&lt;br /&gt;When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What namespaces are necessary to create a localized application? &lt;/strong&gt;&lt;br /&gt;System.Globalization, System.Resources. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does assert() do? &lt;/strong&gt;&lt;br /&gt;In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between the Debug class and Trace class? &lt;/strong&gt;&lt;br /&gt;Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why are there five tracing levels in System.Diagnostics.TraceSwitcher? &lt;/strong&gt;&lt;br /&gt;The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Where is the output of TextWriterTraceListener redirected? &lt;/strong&gt;&lt;br /&gt;To the Console or a text file depending on the parameter passed to the constructor.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are three test cases you should go through in unit testing? &lt;/strong&gt;&lt;br /&gt;Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception  test cases (exceptions are thrown and caught properly).  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you change the value of a variable while debugging a C# application? &lt;/strong&gt;&lt;br /&gt;Yes, if you are debugging via Visual Studio.NET, just go to immediate window.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the implicit name of the parameter that gets passed into the class' set method? &lt;/strong&gt;&lt;br /&gt;Value, and it's datatype depends on whatever variable we're changing.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you inherit from a class in C#? &lt;/strong&gt;&lt;br /&gt;Place a colon and then the name of the base class. Notice that it's double colon in C++.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Does C# support multiple inheritance? &lt;/strong&gt;&lt;br /&gt;No, use interfaces instead.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When you inherit a protected class-level variable, who is it available to?&lt;/strong&gt;&lt;br /&gt;Derived Classes. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the top .NET class that everything is derived from? &lt;/strong&gt;&lt;br /&gt;System.Object.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How's method overriding different from overloading? &lt;/strong&gt;&lt;br /&gt;When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the  same name within the class.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does the keyword virtual mean in the method definition?&lt;/strong&gt;&lt;br /&gt;The method can be over-ridden.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you declare the override method static while the original method is non-static?&lt;/strong&gt;&lt;br /&gt;No, you can't, the signature of the virtual method must remain the same, and only the keyword virtual is changed to keyword override.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you override private virtual methods? &lt;/strong&gt;&lt;br /&gt;No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you prevent your class from being inherited and becoming a base class for some other classes? &lt;/strong&gt;&lt;br /&gt;Yes, that's what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It's the same concept as final class in Java.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you allow class to be inherited, but prevent the method from being over-ridden? &lt;/strong&gt;&lt;br /&gt;Yes, just leave the class public and make the method sealed.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why can't you specify the accessibility modifier for methods inside the interface? &lt;/strong&gt;&lt;br /&gt;They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it's public by default.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you inherit multiple interfaces? And if they have conflicting method names? &lt;/strong&gt;&lt;br /&gt;Yes, why not. &lt;br /&gt;&lt;br /&gt;It's up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you're okay.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between an interface and abstract class?&lt;/strong&gt;&lt;br /&gt;In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How can you overload a method?&lt;/strong&gt;&lt;br /&gt;By having Different parameter data types.&lt;br /&gt;By having different number of parameters.&lt;br /&gt;By having different order of parameters.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?&lt;/strong&gt;&lt;br /&gt;Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between System.String and System.StringBuilder classes? &lt;/strong&gt;&lt;br /&gt;System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Does C# support multiple-inheritance?&lt;/strong&gt;&lt;br /&gt;No, use interfaces instead. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When you inherit a protected class-level variable, who is it available to?&lt;/strong&gt;&lt;br /&gt;The derived class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Are private class-level variables inherited?&lt;/strong&gt;&lt;br /&gt;Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Describe the accessibility modifier "protected internal".&lt;/strong&gt;&lt;br /&gt;It is available to derived classes and classes within the same Assembly (and naturally from the base class it's declared in). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the top .NET class that everything is derived from?&lt;/strong&gt;&lt;br /&gt;System.Object. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the advantage of using System.Text.StringBuilder over System.String?&lt;/strong&gt;&lt;br /&gt;StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time it's being operated on, a new instance is created. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you store multiple data types in System.Array?&lt;/strong&gt;&lt;br /&gt;No. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the .NET class that allows the retrieval of a data element using a unique key?&lt;/strong&gt;&lt;br /&gt;HashTable. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Will the finally block get executed if an exception has not occurred?&lt;/strong&gt;&lt;br /&gt;Yes. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's an abstract class?&lt;/strong&gt;&lt;br /&gt;Abstract class is a class that cannot be instantiated.  An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When do you absolutely have to declare a class as abstract?&lt;/strong&gt;&lt;br /&gt; 1.       When at least one of the methods in the class is abstract.&lt;br /&gt; 2.       When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's an interface?&lt;/strong&gt;&lt;br /&gt;It's an abstract class with public abstract methods all of which must be implemented in the inherited classes.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why can't you specify the accessibility modifier for methods inside the interface?&lt;/strong&gt;&lt;br /&gt;They all must be public.  Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it's public by default. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What's the difference between an interface and abstract class?&lt;/strong&gt;&lt;br /&gt;In an interface class, all methods must be abstract.  In an abstract class some methods can be concrete.  In an interface class, no accessibility modifiers are allowed, which is ok in an abstract class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How is method overriding different from method overloading?&lt;/strong&gt;&lt;br /&gt;When overriding a method, you change the behavior of the method for the derived class.  Overloading a method simply involves having another method with the same name within the class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you declare an override method to be static if the original method is non-static?&lt;/strong&gt;&lt;br /&gt;No. The signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you override private virtual methods?&lt;/strong&gt;&lt;br /&gt;No.  Private methods are not accessible outside the class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you write a class without specifying namespace? Which namespace does it belong to by default? &lt;/strong&gt;&lt;br /&gt;Yes, you can, then the class belongs to global namespace which has no name. For commercial products, naturally, you  wouldn't want global namespace. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a formatter?  &lt;/strong&gt;&lt;br /&gt;A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Different b/w .NET &amp; J2EE?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Differences between J2EE and the .NET Platform&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Vendor Neutrality&lt;/strong&gt;&lt;br /&gt;The .NET platform is not vendor neutral, it is tied to the Microsoft operating systems. But neither are any of the J2EE implementations&lt;br /&gt;Many companies buy into J2EE believing that it will give them vendor neutrality. And, in fact, this is a stated goal of Sun's vision:&lt;br /&gt;A wide variety of J2EE product configurations and implementations, all of which meet the requirements of this specification, are possible. A portable J2EE application will function correctly when successfully deployed in any of these products. (ref : Java 2 Platform Enterprise Edition Specification, v1.3, page 2-7 available at http://java.sun.com/j2ee/)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Overall Maturity&lt;/strong&gt;&lt;br /&gt;Given that the .NET platform has a three year lead over J2EE, it should be no surprise to learn that the .NET platform is far more mature than the J2EE platform. Whereas we have high volume highly reliable web sites using .NET technologies (NASDAQ and Dell being among many examples)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Interoperability and Web Services&lt;/strong&gt;&lt;br /&gt;The .NET platform eCollaboration model is, as I have discussed at length, based on the UDDI and SOAP standards. These standards are widely supported by more than 100 companies. Microsoft, along with IBM and Ariba, are the leaders in this area. Sun is a member of the UDDI consortium and recognizes the importance of the UDDI standards. In a recent press release, Sun's George Paolini, Vice President for the Java Community Development, says: "Sun has always worked to help establish and support open, standards-based technologies that facilitate the growth of network-based applications, and we see UDDI as an important project to establish a registry framework for business-to-business e-commerce”. But while Sun publicly says it believes in the UDDI standards, in reality, Sun has done nothing whatsoever to incorporate any of the UDDI standards into J2EE.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Scalability&lt;/strong&gt;&lt;br /&gt;Typical Comparision w.r.t Systems and their costs&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;J2EE&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Company System   Total Sys.                                             Cost&lt;br /&gt;Bull             Escala T610 c/s                                  16,785  $1,980,179     &lt;br /&gt;IBM              RS/6000 Enterprise Server F80                    16,785  $2,026,681     &lt;br /&gt;Bull             Escala EPC810 c/s                                33,375  $3,037,499     &lt;br /&gt;IBM              RS/6000 Enterprise Server M80                    33,375  $3,097,055     &lt;br /&gt;Bull             Escala EPC2450                                   110,403 $9,563,263     &lt;br /&gt;IBM              IBM eServer pSeries 680 Model 7017-S85           110,403 $9,560,594     &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET platform systems&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Company System        Total Sys.                                     Cost&lt;br /&gt;Dell                 PowerEdge 4400                            16,263  $273,487       &lt;br /&gt;Compaq               ProLiant ML-570-6/700-3P                  20,207  $201,717    &lt;br /&gt;   &lt;br /&gt;Dell                 PowerEdge 6400                            30,231  $334,626       &lt;br /&gt;IBM                  Netfinity 7600 c/s                        32,377  $443,463       &lt;br /&gt;Compaq               ProLiant 8500-X550-64P                    161,720 $3,534,272 &lt;br /&gt;    &lt;br /&gt;Compaq               ProLiant 8500-X700-64P                    179,658 $3,546,582     &lt;br /&gt;Compaq               ProLiant 8500-X550-96P                    229,914 $5,305,571     &lt;br /&gt;Compaq               ProLiant 8500-X700-96P                    262,244 $5,305,571     &lt;br /&gt;Compaq               ProLiant 8500-700-192P                    505,303 $10,003,826    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Framework Support&lt;/strong&gt;&lt;br /&gt;The .NET platform includes such an eCommerce framework called Commerce Server. At this point, there is no equivalent vendor-neutral framework in the J2EE space. With J2EE, you should assume that you will be building your new eCommerce solution from scratch&lt;br /&gt;Moreover, no matter what [J2EE] vendor you choose, if you expect a component framework that will allow you to quickly field complete e-business applications, you are in for a frustrating experience&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Language&lt;/strong&gt;&lt;br /&gt;In the language arena, the choice is about as simple as it gets. J2EE supports Java, and only Java. It will not support any other language in the foreseeable future. The .NET platform supports every language except Java (although it does support a language that is syntactically and functionally equivalent to Java, C#). In fact, given the importance of the .NET platform as a language independent vehicle, it is likely that any language that comes out in the near future will include support for the .NET platform. &lt;br /&gt;Some companies are under the impression that J2EE supports other languages. Although both IBM's WebSphere and BEA's WebLogic support other languages, neither does it through their J2EE technology. There are only two official ways in the J2EE platform to access other languages, one through the Java Native Interface and the other through CORBA interoperability. Sun recommends the later approach. As Sun's Distinguished Scientist and Java Architect Rick Cattell said in a recent interview.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Portability&lt;/strong&gt;&lt;br /&gt;The reason that operating system portability is a possibility with J2EE is not so much because of any inherent portability of J2EE, as it is that most of the J2EE vendors support multiple operating systems. Therefore as long as one sticks with a given J2EE vendor and a given database vendor, moving from one operating system to another should be possible. This is probably the single most important benefit in favor of J2EE over the .NET platform, which is limited to the Windows operating system. It is worth noting, however, that Microsoft has submitted the specifications for C# and a subset of the .NET Framework (called the common language infrastructure) to ECMA, the group that standardizes JavaScript.&lt;br /&gt;J2EE offers an acceptable solution to ISVs when the product must be marketed to non-Windows customers, particularly when the J2EE platform itself can be bundled with the ISV's product as an integrated offering. &lt;br /&gt;If the primary customer base for the ISV is Windows customers, then  the .NET platform should be chosen.  It will provide much better performance at a much lower cost.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Client device independence&lt;/strong&gt;&lt;br /&gt;The major difference being that with Java, it is the presentation tier programmer that determines the ultimate HTML that will be delivered to the client, and with .NET, it is a Visual Studio.NET control. &lt;br /&gt;This Java approach has three problems. First, it requires a lot of code on the presentation tier, since every possible thin client system requires a different code path. Second, it is very difficult to test the code with every possible thin client system. Third, it is very difficult to add new thin clients to an existing application, since to do so involves searching through, and modifying a tremendous amount of presentation tier logic.&lt;br /&gt;The .NET Framework approach is to write device independent code that interacts with visual controls. It is the control, not the programmer, that is responsible for determining what HTML to deliver, based on the capabilities of the client device.. In the .NET Framework model, one can forget that such a thing as HTML even exists!&lt;br /&gt;Conclusion&lt;br /&gt;Sun's J2EE vision is based on a family of specifications that can be implemented by many vendors. It is open in the sense that any company can license and implement the technology, but closed in the sense that it is controlled by a single vendor, and a self contained architectural island with very limited ability to interact outside of itself. One of J2EE's major disadvantages is that the choice of the platform dictates the use of a single programming language, and a programming language that is not well suited for most businesses. One of J2EE's major advantages is that most of the J2EE vendors do offer operating system portability. &lt;br /&gt;Microsoft's .NET platform vision is a family of products rather than specifications, with specifications used primarily to define points of interoperability. The major disadvantage of this approach is that if is limited to the Windows platform, so applications written for the .NET platform can only be run on .NET platforms. Their are several important advantages to the .NET platform:&lt;br /&gt;* The cost of developing applications is much lower, since standard business languages can be used and device independent presentation tier logic can be written.&lt;br /&gt;* The cost of running applications is much lower, since commodity hardware platforms (at 1/5 the cost of their Unix counterparts) can be used.&lt;br /&gt;* The ability to scale up is much greater, with the proved ability to support at least ten times the number of clients any J2EE platform has shown itself able to support.&lt;br /&gt;* Interoperability is much stronger, with industry standard eCollaboration built into the platform.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the Main Features of .NET platform?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Features of .NET Platform are :-&lt;br /&gt;&lt;strong&gt;Common Language Runtime &lt;/strong&gt;&lt;br /&gt;Explains the features and benefits of the common language runtime, a run-time environment that manages the execution of code and provides services that simplify the development process. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Assemblies &lt;/strong&gt;&lt;br /&gt;Defines the concept of assemblies, which are collections of types and resources that form logical units of functionality. Assemblies are the fundamental units of deployment, version control, reuse, activation scoping, and security permissions. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Application Domains &lt;/strong&gt;&lt;br /&gt;Explains how to use application domains to provide isolation between applications. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Runtime Hosts &lt;/strong&gt;&lt;br /&gt;Describes the runtime hosts supported by the .NET Framework, including ASP.NET, Internet Explorer, and shell executables. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Common Type System &lt;/strong&gt;&lt;br /&gt;Identifies the types supported by the common language runtime. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Metadata and Self-Describing Components &lt;/strong&gt;&lt;br /&gt;Explains how the .NET Framework simplifies component interoperation by allowing compilers to emit additional declarative information, or metadata, into all modules and assemblies. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Cross-Language Interoperability &lt;/strong&gt;&lt;br /&gt;Explains how managed objects created in different programming languages can interact with one another. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Framework Security &lt;/strong&gt;&lt;br /&gt;Describes mechanisms for protecting resources and code from unauthorized code and unauthorized users. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Framework Class Library &lt;/strong&gt;&lt;br /&gt;Introduces the library of types provided by the .NET Framework, which expedites and optimizes the development process and gives you access to system functionality. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the use of JIT ?&lt;/strong&gt;&lt;br /&gt;JIT (Just - In - Time) is a compiler which converts MSIL code to Native Code (ie.. CPU-specific code that runs on the same computer architecture).&lt;br /&gt;Because the common language runtime supplies a JIT compiler for each supported CPU architecture, developers can write a set of MSIL that can be JIT-compiled and run on computers with different architectures. However, your managed code will run only on a specific operating system if it calls platform-specific native APIs, or a platform-specific class library.&lt;br /&gt;JIT compilation takes into account the fact that some code might never get called during execution. Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as needed during execution and stores the resulting native code so that it is accessible for subsequent calls. The loader creates and attaches a stub to each of a type's methods when the type is loaded. On the initial call to the method, the stub passes control to the JIT compiler, which converts the MSIL for that method into native code and modifies the stub to direct execution to the location of the native code. Subsequent calls of the JIT-compiled method proceed directly to the native code that was previously generated, reducing the time it takes to JIT-compile and run the code.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What meant of assembly &amp; global assembly cache (gac) &amp; Meta data.&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Assembly&lt;/strong&gt; :-- An assembly is the primary building block of a .NET based application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or as accessible by code outside that unit. It overcomes the problem of 'dll Hell'.The .NET Framework uses assemblies as the fundamental unit for several purposes: &lt;br /&gt;1.Security  &lt;br /&gt;2.Type Identity  &lt;br /&gt;3.Reference Scope  &lt;br /&gt;4.Versioning  &lt;br /&gt;5.Deployment &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Global Assembly Cache&lt;/strong&gt; :-- Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache(GAC). GAC is a machine wide a local cache of assemblies maintained by the .NET Framework. We can register the assembly to global assembly cache by using gacutil command.&lt;br /&gt;&lt;br /&gt;We can Navigate to the GAC directory, C:\winnt\Assembly in explore. In the tools menu select the cache properties; in the windows displayed you can set the memory limit in MB used by the GAC&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MetaData&lt;/strong&gt; :--Assemblies have Manifests. This Manifest contains Metadata information of the Module/Assembly as well as it contains detailed Metadata of other assemblies/modules references (exported). It's the Assembly Manifest which differentiates between an Assembly and a Module. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the mobile devices supported by .net platform&lt;/strong&gt;&lt;br /&gt;The Microsoft .NET Compact Framework is designed to run on mobile devices such as mobile phones, Personal Digital Assistants (PDAs), and embedded devices. The easiest way to develop and test a Smart Device Application is to use an emulator.&lt;br /&gt;&lt;br /&gt;These devices are divided into two main divisions: &lt;br /&gt;1) Those that are directly supported by .NET (Pocket PCs, i-Mode phones, and WAP devices)&lt;br /&gt;2) Those that are not (Palm OS and J2ME-powered devices).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is GUID , why we use it and where?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;GUID &lt;/strong&gt;:-- GUID is Short form of Globally Unique Identifier, a unique 128-bit number that is produced by the Windows OS or by some Windows applications to identify a particular component, application, file, database entry, and/or user. For instance, a Web site may generate a GUID and assign it to a user's browser to record and track the session. A GUID is also used in a Windows registry to identify COM DLLs. Knowing where to look in the registry and having the correct GUID yields a lot information about a COM object (i.e., information in the type library, its physical location, etc.). Windows also identifies user accounts by a username (computer/domain and username) and assigns it a GUID. Some database administrators even will use GUIDs as primary key values in databases. &lt;br /&gt;GUIDs can be created in a number of ways, but usually they are a combination of a few unique settings based on specific point in time (e.g., an IP address, network MAC address, clock date/time, etc.). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Describe the difference between inline and code behind - which is best in a loosely coupled solution&lt;/strong&gt;&lt;br /&gt;ASP.NET supports two modes of page development: Page logic code that is written inside runat="server"&gt; blocks within an .aspx file and dynamically compiled the first time the page is requested on the server. Page logic code that is written within an external class that is compiled prior to deployment on a server and linked ""behind"" the .aspx file at run time.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Whats MSIL, and why should my developers need an appreciation of it if at all?&lt;/strong&gt;&lt;br /&gt;When compiling the source code to managed code, the compiler translates the source into Microsoft intermediate language (MSIL). This is a CPU-independent set of instructions that can efficiently be converted to native code. Microsoft intermediate language (MSIL) is a translation used as the output of a number of compilers. It is the input to a just-in-time (JIT) compiler. The Common Language Runtime includes a JIT compiler for the conversion of MSIL to native code. &lt;br /&gt;&lt;br /&gt;Before Microsoft Intermediate Language (MSIL) can be executed it, must be converted by the .NET Framework just-in-time (JIT) compiler to native code. This is CPU-specific code that runs on the same computer architecture as the JIT compiler. Rather than using time and memory to convert all of the MSIL in a portable executable (PE) file to native code. It converts the MSIL as needed whilst executing, then caches the resulting native code so its accessible for any subsequent calls. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How many .NET languages can a single .NET DLL contain?&lt;/strong&gt;&lt;br /&gt;One&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What type of code (server or client) is found in a Code-Behind class? &lt;/strong&gt;&lt;br /&gt;Server&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is an assembly? &lt;/strong&gt;&lt;br /&gt;Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How many classes can a single .NET DLL contain? &lt;/strong&gt;&lt;br /&gt;Unlimited.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between string and String ?&lt;/strong&gt;&lt;br /&gt;No difference&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is manifest?&lt;/strong&gt;&lt;br /&gt;It is the metadata that describes the assemblies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is metadata?&lt;/strong&gt;&lt;br /&gt;Metadata is machine-readable information about a resource, or ""data about data."" Such information might include details on content, format, size, or other characteristics of a datasource. In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the types of assemblies?&lt;/strong&gt;&lt;br /&gt;There are four types of assemblies in .NET:&lt;br /&gt;&lt;strong&gt;Static assemblies&lt;/strong&gt;&lt;br /&gt;These are the .NET PE files that you create at compile time. &lt;br /&gt;&lt;strong&gt;Dynamic assemblies&lt;/strong&gt;&lt;br /&gt;These are PE-formatted, in-memory assemblies that you dynamically create at runtime using the classes in the System.Reflection.Emit namespace.&lt;br /&gt;&lt;strong&gt;Private assemblies&lt;/strong&gt;&lt;br /&gt;These are static assemblies used by a specific application.&lt;br /&gt;&lt;strong&gt;Public or shared assemblies&lt;/strong&gt;&lt;br /&gt;These are static assemblies that must have a unique shared name and can be used by any application.&lt;br /&gt;&lt;br /&gt;An application uses a private assembly by referring to the assembly using a static path or through an XML-based application configuration file. While the CLR doesn't enforce versioning policies-checking whether the correct version is used-for private assemblies, it ensures that an application uses the correct shared assemblies with which the application was built. Thus, an application uses a specific shared assembly by referring to the specific shared assembly, and the CLR ensures that the correct version is loaded at runtime.&lt;br /&gt;In .NET, an assembly is the smallest unit to which you can associate a version number;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are delegates?where are they used ?&lt;/strong&gt;&lt;br /&gt;A delegate defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;When do you use virutal keyword?.&lt;/strong&gt;&lt;br /&gt;When we need to override a method of the base class in the sub class, then we give the virtual keyword in the base class method. This makes the method in the base class to be overridable. Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are class access modifiers ?&lt;/strong&gt;&lt;br /&gt;Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers: &lt;br /&gt;· Public     - Access is not restricted.&lt;br /&gt;· Protected  - Access is limited to the containing class or types derived from the containing class.&lt;br /&gt;· Internal   - Access is limited to the current assembly.&lt;br /&gt;· Protected inertnal - Access is limited to the current assembly or types derived · from the containing class.&lt;br /&gt;· Private    - Access is limited to the containing type.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What Is Boxing And Unboxing?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Boxing&lt;/strong&gt; :- Boxing is an implicit conversion of a value type to the type object type&lt;br /&gt;Eg:-&lt;br /&gt;Consider the following declaration of a value-type variable:&lt;br /&gt;int i = 123;&lt;br /&gt;object o = (object) i;&lt;br /&gt;Boxing Conversion&lt;br /&gt;&lt;strong&gt;UnBoxing &lt;/strong&gt;:- Unboxing is an explicit conversion from the type object to a value type&lt;br /&gt;Eg:&lt;br /&gt;int i = 123;          // A value type&lt;br /&gt;object box = i;       // Boxing&lt;br /&gt;int j = (int)box;     // Unboxing&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Value type and refernce type in .Net?.&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Value Type :&lt;/strong&gt; A variable of a value type always contains a value of that type. The assignment to a variable of a value type creates a copy of the assigned value, while the assignment to a variable of a reference type creates a copy of the reference but not of the referenced object.&lt;br /&gt;The value types consist of two main categories: &lt;br /&gt;* Stuct Type&lt;br /&gt;* Enumeration Type&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reference Type :&lt;/strong&gt;Variables of reference types, referred to as objects, store references to the actual data. This section introduces the following keywords used to declare reference types: &lt;br /&gt;* Class&lt;br /&gt;* Interface&lt;br /&gt;* Delegate&lt;br /&gt;This section also introduces the following built-in reference types: &lt;br /&gt;* object &lt;br /&gt;* string &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between structures and enumeration?.&lt;/strong&gt;&lt;br /&gt;Unlike classes, structs are value types and do not require heap allocation. A variable of a struct type directly contains the data of the struct, whereas a variable of a class type contains a reference to the data. They are derived from System.ValueType class.&lt;br /&gt;Enum-&gt;An enum type is a distinct type that declares a set of named constants.They  are strongly typed constants. They are unique types that allow to declare symbolic names to integral values. Enums are value types, which means they contain their own value, can't inherit or be inherited from and assignment copies the value of one enum to another.&lt;br /&gt;public enum Grade&lt;br /&gt;{&lt;br /&gt;   A,&lt;br /&gt;   B,&lt;br /&gt;   C&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is namespaces?&lt;/strong&gt;&lt;br /&gt;Namespace is a logical naming scheme for group related types.Some class types that logically belong together they can be put into a common namespace. They prevent namespace collisions and they provide scoping. They are imported as "using" in C# or "Imports" in Visual Basic. It seems as if these directives specify a particular assembly, but they don't. A namespace can span multiple assemblies, and an assembly can define multiple namespaces. When the compiler needs the definition for a class type, it tracks  through each of the different imported namespaces to the type name and searches each referenced assembly until it is found.&lt;br /&gt;Namespaces can be nested. This is very similar to packages in Java as far as scoping is concerned.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you create shared assemblies?&lt;/strong&gt;&lt;br /&gt;Just look through the definition of Assemblies..&lt;br /&gt;   *  An Assembly is a  logical unit of code&lt;br /&gt;   * Assembly physically exist as DLLs or EXEs&lt;br /&gt;   * One assembly can contain one or more files&lt;br /&gt;   * The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs&lt;br /&gt;   * When you compile your source code by default the exe/dll generated is actually an assembly&lt;br /&gt;   * Unless your code is bundled as assembly it can not be used in any other application&lt;br /&gt;   * When you talk about version of a component you are actually talking about version of the assembly to which the component belongs.&lt;br /&gt;   * Every assembly file contains information about itself. This information is called as Assembly Manifest.&lt;br /&gt;Following steps are involved in creating shared assemblies :&lt;br /&gt;   * Create your DLL/EXE source code&lt;br /&gt;   * Generate unique assembly name using SN utility&lt;br /&gt;   * Sign your DLL/EXE with the private key by modifying AssemblyInfo file&lt;br /&gt;   * Compile your DLL/EXE&lt;br /&gt;   * Place the resultant DLL/EXE in global assembly cache using AL utility&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is global assembly cache?&lt;/strong&gt;&lt;br /&gt;Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.&lt;br /&gt; There are several ways to deploy an assembly into the global assembly cache: &lt;br /&gt;1. Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache. &lt;br /&gt;2. Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK. &lt;br /&gt;3. Use Windows Explorer to drag assemblies into the cache.   &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is MSIL?&lt;/strong&gt;&lt;br /&gt;When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be run, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture.&lt;br /&gt;When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type's members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Jit compilers?.how many are available in clr?&lt;/strong&gt;&lt;br /&gt;Just-In-Time compiler- it converts the language that you write in .Net into machine language that a computer can understand. there are tqo types of JITs one  is memory optimized &amp; other  is performace optimized.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is tracing?Where it used. Explain few methods available&lt;/strong&gt;&lt;br /&gt;Tracing refers to collecting information about the application while it is running. You use tracing  information to troubleshoot an application.&lt;br /&gt;Tracing allows us to observe and correct programming errors. Tracing enables you to record information in various log files about the errors that might occur at run time. You can analyze these log files to find the cause of the errors.&lt;br /&gt;In .NET we have objects called Trace Listeners. A listener is an object that receives the trace output and outputs it somewhere; that somewhere could be a window in your development environment, a file on your hard drive, a Windows Event log, a SQL Server or Oracle database, or any other customized data store. &lt;br /&gt;The System.Diagnostics namespace provides the interfaces, classes, enumerations and structures that are used for tracing The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs.&lt;br /&gt;All Trace Listeners have the following functions. Functionality of these functions is same except that the target media for the tracing output is determined by the Trace Listener. &lt;br /&gt;Method Name&lt;br /&gt;Result Fail    Outputs the specified text with the Call Stack.&lt;br /&gt;Write          Outputs the specified text.&lt;br /&gt;WriteLine      Outputs the specified text and a carriage return.&lt;br /&gt;Flush          Flushes the output buffer to the target media.&lt;br /&gt;Close          Closes the output stream in order to not receive the  tracing/debugging output. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to set the debug mode?&lt;/strong&gt;&lt;br /&gt;Debug Mode for ASP.NET applications - To set ASP.NET appplication in debugging mode, edit the application's web.config and assign the "debug" attribute in &lt; compilation &gt; section to "true" as show below:&lt;br /&gt;&lt; configuration &gt;&lt;br /&gt;  &lt; system.web &gt;&lt;br /&gt;    &lt; compilation defaultLanguage="vb" debug="true" / &gt;&lt;br /&gt;....&lt;br /&gt;...&lt;br /&gt;..&lt;br /&gt;&lt; / configuration &gt;&lt;br /&gt;This case-sensitive attribute 'debug tells ASP.NET to generate symbols for dynamically generated files and enables the debugger to attach to the ASP.NET application. ASP.NET will detect this change automatically, without the need to restart the server. Debug Mode for ASP.NET Webservices - Debugging an XML Web service created with ASP.NET is similar to the debugging an ASP.NET Web application.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the property available to check if the page posted or not?&lt;/strong&gt;&lt;br /&gt;The Page_Load event handler in the page checks for IsPostBack property value, to ascertain whether the page is posted. The Page.IsPostBack gets a value indicating whether the page is being loaded in response to the client postback, or it is for the first time. The value of Page.IsPostBack is True, if the page is being loaded in response to the client postback; while its value is False, when the page is loaded for the first time. The Page.IsPostBack property facilitates execution of certain routine in Page_Load, only once (for e.g. in Page load, we need to set default value in controls, when page is loaded for the first time. On post back, we check for true value for IsPostback value and then invoke server-side code to &lt;br /&gt;update data).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Which are the abstract classes available under system.xml namespace?&lt;/strong&gt;&lt;br /&gt;The System.XML namespace provides XML related processing ability in .NET framework. XmlReader and XMLWriter are the two abstract classes at the core of .NET Framework XML classes: &lt;br /&gt;1. XmlReader provides a fast, forward-only, read-only cursor for processing an XML document stream.&lt;br /&gt;2. XmlWriter provides an interface for producing XML document streams that conform to the W3C's XML standards.&lt;br /&gt;Both XmlReader and XmlWriter are abstract base classes, which define the functionality that all derived classes must support.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is it possible to use multipe inheritance in .net?&lt;/strong&gt;&lt;br /&gt;Multiple Inheritance is an ability to inherit from more than one base class i.e.  ability of a class to have more than one superclass, by inheriting from different sources and thus combine separately-defined behaviors in a single class. There are two types of multiple inheritance: multiple type/interface inheritance and multiple implementation inheritance. C# &amp; VB.NET supports only multiple type/interface inheritance, i.e.&lt;br /&gt;you can derive an class/interface from multiple interfaces. There is no support for multiple implementation inheritance in .NET. That means a class can only derived from one class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the derived classes from xmlReader and xmlWriter?&lt;/strong&gt;&lt;br /&gt;Both XmlReader and XmlWriter are abstract base classes, which define the functionality that all derived classes must support.&lt;br /&gt;There are three concrete implementations of XmlReader:&lt;br /&gt;       1.XmlTextReader&lt;br /&gt;       2.XmlNodeReader&lt;br /&gt;       3.XmlValidatingReader&lt;br /&gt;There are two concrete implementations of XmlWriter:&lt;br /&gt;       1.XmlTextWriter&lt;br /&gt;       2.XmlNodeWriter&lt;br /&gt;XmlTextReader and XmlTextWriter support reading data to/from text-based stream, while XmlNodeReader and XmlNodeWriter are designed for working with in-memory DOM tree structure. The custom readers and writers can also be developed to extend the built-in functionality of XmlReader and XmlWriter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is managed and unmanaged code?&lt;/strong&gt;&lt;br /&gt;The .NET framework provides several core run-time services to the programs that run within it - for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. i.e., code executing under the control of the CLR is called managed code. For example, any code written in C# or Visual Basic .NET is managed code.&lt;br /&gt;Code that runs outside the CLR is referred to as "unmanaged code." COM components, ActiveX components, and Win32 API functions are examples of unmanaged code.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How you deploy .NET assemblies?&lt;/strong&gt;&lt;br /&gt;One way is simply use xcopy. others are use and the setup projects in .net. and one more way is use of no touch deployment.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Globalizationa and Localization ?&lt;/strong&gt;&lt;br /&gt;Globalization is the process of creating an application that meets the needs of users from multiple cultures. It includes using the correct&lt;br /&gt;currency, date and time format, calendar, writing direction, sorting rules, and other issues. Accommodating these cultural differences in an application is called localization.Using classes of System.Globalization namespace, you can set application's current culture.&lt;br /&gt;This can be achieved by using any of the following 3 approaches.&lt;br /&gt;      1.      Detect and redirect&lt;br /&gt;      2.      Run-time adjustment&lt;br /&gt;      3.      Using Satellite assemblies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are Resource Files ? How are they used in .NET?&lt;/strong&gt;&lt;br /&gt;Resource files are the files containing data that is logically deployed with an application.These files can contain data in a number of formats including strings, images and persisted objects. It has the main advantage of If we store data in these files then we don't need to compile these if the data get changed. In .NET we basically require them storing culture specific informations by localizing application's resources. You can deploy your resources using satellite assemblies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Difference between Dispose and Finallize method?&lt;/strong&gt;&lt;br /&gt;Finalize method is used to free the memory used by some unmanaged resources like window handles (HWND). It's similar to the destructor syntax in C#. The GC calls this method when it founds no more references to the object. But, In some cases we may need release the memory used by the resources explicitely.To release the memory explicitly we need to implement the Dispose method of IDisposable interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is encapsulation ?&lt;/strong&gt;&lt;br /&gt;Encapsulation is the ability to hide the internal workings of an object's behavior and its data. For instance, let's say you have a object named Bike and this object has a method named start(). When you create an instance of a Bike object and call its start() method you are not worried about what happens to accomplish this, you just want to make sure the state of the bike is changed to 'running' afterwards. This kind of behavior hiding is encapsulation and it makes programming much easier.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How can you prevent your class to be inherated further?&lt;/strong&gt;&lt;br /&gt;By setting Sealed - Key word&lt;br /&gt; public sealed class Planet&lt;br /&gt; {&lt;br /&gt;             //code goes here&lt;br /&gt; }&lt;br /&gt;class Moon:Planet&lt;br /&gt; {&lt;br /&gt;     //Not allowed as base class is sealed&lt;br /&gt; }&lt;br /&gt;What is GUID and why we need to use it and in what condition? How this is created.&lt;br /&gt;A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever  a unique identifier is required. Such an identifier has a very low probability of being duplicated. Visual Studio .NET IDE has a utility under the tools menu to generate GUIDs.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why do you need to serialize.?&lt;/strong&gt;&lt;br /&gt;We need to serialize the object,if you want to pass object from one  computer/application domain to another.Process of converting complex objects into stream of bytes that can be persisted or  transported.Namespace for serialization is System.Runtime.Serialization.The  ISerializable interface allows you to make any class Serializable..NET framework features 2 serializing method.&lt;br /&gt;1.Binary Serialization&lt;br /&gt;2.XML Serialization&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is inline schema, how does it works?&lt;/strong&gt;&lt;br /&gt;Schemas can be included inside of XML file is called Inline Schemas.This is useful  when it is inconvenient to physically seprate the schema and the XML document.A  schema is an XML document that defines the structure, constraints, data types, and  relationships of the elements that constitute the data contained inside the XML  document or in another XML document.Schema can be an external file which uses the  XSD or XDR extension called external schema. Inline schema can take place even when validation is turned off.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Describe the advantages of writing a managed code application instead of unmanaged one. What's involved in certain piece of code being managed?&lt;/strong&gt; &lt;br /&gt;"Advantage includes automatic garbage collection,memory management,security,type checking,versioning&lt;br /&gt;&lt;br /&gt;Managed code is compiled for the .NET run-time environment. It runs in the Common Language Runtime (CLR), which is the heart of the .NET Framework. The CLR provides services such as security, memory management, and cross-language integration. Managed applications written to take advantage of the features of the CLR perform more efficiently and safely, and take better advantage of developers existing expertise in languages that support the .NET Framework. &lt;br /&gt;&lt;br /&gt;Unmanaged code includes all code written before the .NET Framework was introduced—this includes code written to use COM, native Win32, and Visual Basic 6. Because it does not run inside the .NET environment, unmanaged code cannot make use of any .NET managed facilities."&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are multicast delegates? Give an example?&lt;/strong&gt;&lt;br /&gt;Delegate that can have more than one element in its invocation List.&lt;br /&gt;using System;&lt;br /&gt;namespace SampleMultiCastDelegate&lt;br /&gt;{&lt;br /&gt;  class MultiCast&lt;br /&gt;  {&lt;br /&gt;    public delegate string strMultiCast(string s);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;MainClass defines the static methods having same signature as delegate.&lt;br /&gt;using System;&lt;br /&gt;namespace SampleMultiCastDelegate&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt;  public class MainClass&lt;br /&gt;  {&lt;br /&gt;    public MainClass()&lt;br /&gt;    { &lt;br /&gt;    }&lt;br /&gt;public static string Jump(string s)&lt;br /&gt;{&lt;br /&gt;     Console.WriteLine("Jump");&lt;br /&gt;     return String.Empty;&lt;br /&gt; }&lt;br /&gt;    public static string Run(string s)&lt;br /&gt;    {&lt;br /&gt;      Console.WriteLine("Run"); &lt;br /&gt;      return String.Empty;&lt;br /&gt;    }&lt;br /&gt;    public static string Walk(string s)&lt;br /&gt;    {&lt;br /&gt;      Console.WriteLine("Walk"); &lt;br /&gt;      return String.Empty;      &lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;The Main class:&lt;br /&gt;using System;&lt;br /&gt;using System.Threading;&lt;br /&gt;namespace SampleMultiCastDelegate&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt;  public class MainMultiCastDelegate&lt;br /&gt;  {&lt;br /&gt;    public static void Main()&lt;br /&gt;    {&lt;br /&gt;      MultiCast.strMultiCast  Run,Walk,Jump;&lt;br /&gt;      MultiCast.strMultiCast    myDelegate;&lt;br /&gt;       ///here mydelegate used the Combine method of System.MulticastDelegate&lt;br /&gt;      ///and the delegates combine  &lt;br /&gt;      myDelegate=(MultiCast.strMultiCast)System.Delegate.Combine(Run,Walk); &lt;br /&gt;               &lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can a nested object be used in Serialization ?&lt;/strong&gt;&lt;br /&gt;Yes. If a class that is to be serialized contains references to objects of other classes, and if those classes have been marked as serializable, then their objects are serialized too.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Difference between int and int32 ?&lt;/strong&gt;&lt;br /&gt;Both are same. System.Int32 is a .NET class. Int is an alias name for System.Int32.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Describe the difference between a Thread and a Process?&lt;/strong&gt; &lt;br /&gt;A Process is an instance of an running application. And a thread is the Execution stream of the Process. A process can have multiple Thread.&lt;br /&gt;When a process starts a specific memory area is allocated to it. When there is multiple thread in a process, each thread gets a memory for storing the variables in it and plus they can access to the global variables which is common for all the thread. Eg.A Microsoft Word is a Application. When you open a word file,an instance of the Word starts and a process is allocated to this instance which has one thread.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between an EXE and a DLL? &lt;/strong&gt;&lt;br /&gt;You can create an objects of Dll but not of the EXE.&lt;br /&gt;Dll is an In-Process Component whereas EXE is an OUt-Process Component.&lt;br /&gt;Exe is for single use whereas you can use Dll for multiple use.&lt;br /&gt;Exe can be started as standalone where dll cannot be.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is strong-typing versus weak-typing? Which is preferred? Why? &lt;/strong&gt;&lt;br /&gt;Strong typing implies that the types of variables involved in operations are associated to the variable, checked at compile-time, and require explicit conversion; weak typing implies that they are associated to the value, checked at run-time, and are implicitly converted as required. (Which is preferred is a disputable point, but I personally prefer strong typing because I like my errors to be found as soon as possible.)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a PID? How is it useful when troubleshooting a system? &lt;/strong&gt;&lt;br /&gt;PID is the process Id of the application in Windows. Whenever a process starts running in the Windows environment, it is associated with an individual process Id or PID. &lt;br /&gt;The PID (Process ID) a unique number for each item on the Process Tab, Image Name list.&lt;br /&gt;&lt;strong&gt;How do you get the PID to appear?&lt;/strong&gt;&lt;br /&gt; In Task Manger, select the View menu, then select columns and check PID (Process Identifier).&lt;br /&gt;In Linux, PID is used to debug a process explicitly. However we cannot do this in a windows environment.&lt;br /&gt;Microsoft has launched a SDK called as Microsoft Operations Management (MOM). This uses the PID to find out which dll’s have been loaded by a process in the memory. This is essentially helpful in situations where the Process which has a memory leak is to be traced to a erring dll. Personally I have never used a PID, our Windows debugger does the things required to find out. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the GAC? What problem does it solve?&lt;/strong&gt;&lt;br /&gt;Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies that are to be shared by several applications on the computer. This area is typically the folder under windows or winnt in the machine. &lt;br /&gt;All the assemblies that need to be shared across applications need to be done through the Global assembly Cache only. However it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.&lt;br /&gt;There are several ways to deploy an assembly into the global assembly cache: &lt;br /&gt;1. Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache. &lt;br /&gt;2. Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK. &lt;br /&gt;3. Use Windows Explorer to drag assemblies into the cache. &lt;br /&gt;GAC solves the problem of DLL Hell and DLL versioning. Unlike earlier situations, GAC can hold two assemblies of the same name but different version. This ensures that the applications which access a particular assembly continue to access the same assembly even if another version of that assembly is installed on that machine.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Describe what an Interface is and how it’s different from a Class. &lt;/strong&gt;&lt;br /&gt;An interface is a structure of code which is similar to a class. An interface is a prototype for a class and is useful from a logical design perspective. Interfaces provide a means to define the protocols for a class without worrying about the implementation details. The syntax for creating interfaces follows: &lt;br /&gt;&lt;br /&gt;interface Identifier {&lt;br /&gt;  InterfaceBody&lt;br /&gt;}&lt;br /&gt;Identifier is the name of the interface and InterfaceBody refers to the abstract methods and static final variables that make up the interface. Because it is assumed that all the methods in an interface are abstract, it isn't necessary to use the abstract keyword&lt;br /&gt;&lt;br /&gt;An interface is a description of some of the members available from a class. In practice, the syntax typically looks similar to a class definition, except that there's no code defined for the methods — just their name, the arguments passed and the type of the value returned.&lt;br /&gt;&lt;br /&gt;So what good is it? None by itself. But you create an interface so that classes will implement it.&lt;br /&gt;&lt;br /&gt;But what does it mean to implement an interface. The interface acts as a contract or promise. If a class implements an interface, then it must have the properties and methods of the interface defined in the class. This is enforced by the compiler.&lt;br /&gt;Broadly the differentiators between classes and interfaces is as follows &lt;br /&gt;• Interface should not have any implementation.&lt;br /&gt;• Interface can not create any instance.&lt;br /&gt;• Interface should provide high level abstraction from the implementation.&lt;br /&gt;• Interface can have multiple inheritances. &lt;br /&gt;• Default access level of the interface is public.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?&lt;/strong&gt; &lt;br /&gt;ASP.NET Web services and .NET Remoting provide a full suite of design options for cross-process and cross-plaform communication in distributed applications. In general, ASP.NET Web services provide the highest levels of interoperability with full support for WSDL and SOAP over HTTP, while .NET Remoting is designed for common language runtime type-system fidelity and supports additional data format and communication channels. Hence if we looking cross-platform communication than web services is the choice coz for .NET remoting .Net framework is requried which may or may not present for the other platform.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Serialization and Metadata&lt;/strong&gt;&lt;br /&gt;ASP.NET Web services rely on the System.Xml.Serialization.XmlSerializer class to marshal data to and from SOAP messages at runtime. For metadata, they generate WSDL and XSD definitions that describe what their messages contain. The reliance on pure WSDL and XSD makes ASP.NET Web services metadata portable; it expresses data structures in a way that other Web service toolkits on different platforms and with different programming models can understand. In some cases, this imposes constraints on the types you can expose from a Web service—XmlSerializer will only marshal things that can be expressed in XSD. Specifically, XmlSerializer will not marshal object graphs and it has limited support for container types. &lt;br /&gt;.NET Remoting relies on the pluggable implementations of the IFormatter interface used by the System.Runtime.Serialization engine to marshal data to and from messages. There are two standard formatters, System.Runtime.Serialization.Formatters.Binary.BinaryFormatter and System.Runtime.Serialization.Formatters.Soap.SoapFormatter. The BinaryFormatter and SoapFormatter, as the names suggest, marshal types in binary and SOAP format respectively. For metadata, .NET Remoting relies on the common language runtime assemblies, which contain all the relevant information about the data types they implement, and expose it via reflection. The reliance on the assemblies for metadata makes it easy to preserve the full runtime type-system fidelity. As a result, when the .NET Remoting plumbing marshals data, it includes all of a class's public and private members; handles object graphs correctly; and supports all container types (e.g., System.Collections.Hashtable). However, the reliance on runtime metadata also limits the reach of a .NET Remoting system—a client has to understand .NET constructs in order to communicate with a .NET Remoting endpoint. In addition to pluggable formatters, the .NET Remoting layer supports pluggable channels, which abstract away the details of how messages are sent. There are two standard channels, one for raw TCP and one for HTTP. Messages can be sent over either channel independent of format. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Distributed Application Design: ASP.NET Web Services vs. .NET Remoting&lt;/strong&gt;&lt;br /&gt;ASP.NET Web services favor the XML Schema type system, and provide a simple programming model with broad cross-platform reach. .NET Remoting favors the runtime type system, and provides a more complex programming model with much more limited reach. This essential difference is the primary factor in determining which technology to use. However, there are a wide range of other design factors, including transport protocols, host processes, security, performance, state management, and support for transactions to consider as well.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;br /&gt;Since ASP.NET Web services rely on HTTP, they integrate with the standard Internet security infrastructure. ASP.NET leverages the security features available with IIS to provide strong support for standard HTTP authentication schemes including Basic, Digest, digital certificates, and even Microsoft® .NET Passport. (You can also use Windows Integrated authentication, but only for clients in a trusted domain.) One advantage of using the available HTTP authentication schemes is that no code change is required in a Web service; IIS performs authentication before the ASP.NET Web services are called. ASP.NET also provides support for .NET Passport-based authentication and other custom authentication schemes. ASP.NET supports access control based on target URLs, and by integrating with the .NET code access security (CAS) infrastructure. SSL can be used to ensure private communication over the wire.&lt;br /&gt;&lt;br /&gt;Although these standard transport-level techniques to secure Web services are quite effective, they only go so far. In complex scenarios involving multiple Web services in different trust domains, you have to build custom ad hoc solutions. Microsoft and others are working on a set of security specifications that build on the extensibility of SOAP messages to offer message-level security capabilities. One of these is the XML Web Services Security Language (WS-Security), which defines a framework for message-level credential transfer, message integrity, and message confidentiality.&lt;br /&gt;&lt;br /&gt;As noted in the previous section, the .NET Remoting plumbing does not secure cross-process invocations in the general case. A .NET Remoting endpoint hosted in IIS with ASP.NET can leverage all the same security features available to ASP.NET Web services, including support for secure communication over the wire using SSL. If you are using the TCP channel or the HTTP channel hosted in processes other than aspnet_wp.exe, you have to implement authentication, authorization and privacy mechanisms yourself. &lt;br /&gt;&lt;br /&gt;One additional security concern is the ability to execute code from a semi-trusted environment without having to change the default security policy. ASP.NET Web Services client proxies work in these environments, but .NET Remoting proxies do not. In order to use a .NET Remoting proxy from a semi-trusted environment, you need a special serialization permission that is not given to code loaded from your intranet or the Internet by default. If you want to use a .NET Remoting client from within a semi-trusted environment, you have to alter the default security policy for code loaded from those zones. In situations where you are connecting to systems from clients running in a sandbox—like a downloaded Windows Forms application, for instance—ASP.NET Web Services are a simpler choice because security policy changes are not required.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conceptually, what is the difference between early-binding and late-binding? &lt;/strong&gt;&lt;br /&gt;Early binding – Binding at Compile Time&lt;br /&gt;Late Binding – Binding at Run Time&lt;br /&gt;Early binding implies that the class of the called object is known at compile-time; late-binding implies that the class is not known until run-time, such as a call through an interface or via Reflection.&lt;br /&gt;Early binding is the preferred method. It is the best performer because your application binds directly to the address of the function being called and there is no extra overhead in doing a run-time lookup. In terms of overall execution speed, it is at least twice as fast as late binding.&lt;br /&gt;Early binding also provides type safety. When you have a reference set to the component's type library, Visual Basic provides IntelliSense support to help you code each function correctly. Visual Basic also warns you if the data type of a parameter or return value is incorrect, saving a lot of time when writing and debugging code.&lt;br /&gt;Late binding is still useful in situations where the exact interface of an object is not known at design-time. If your application seeks to talk with multiple unknown servers or needs to invoke functions by name (using the Visual Basic 6.0 CallByName function for example) then you need to use late binding. Late binding is also useful to work around compatibility problems between multiple versions of a component that has improperly modified or adapted its interface between versions.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is an Assembly Qualified Name? Is it a filename? How is it different? &lt;/strong&gt;&lt;br /&gt;An assembly qualified name isn't the filename of the assembly; it's the internal name of the assembly combined with the assembly version, culture, and public key, thus making it unique.&lt;br /&gt;e.g. (""System.Xml.XmlDocument, System.Xml, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"")&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How is a strongly-named assembly different from one that isn’t strongly-named?&lt;/strong&gt; &lt;br /&gt;Strong names are used to enable the stricter naming requirements associated with shared assemblies. These strong names are created by a .NET utility – sn.exe&lt;br /&gt;Strong names have three goals: &lt;br /&gt;· Name uniqueness. Shared assemblies must have names that are globally unique. &lt;br /&gt;· Prevent name spoofing. Developers don't want someone else releasing a subsequent version of one of your assemblies and falsely claim it came from you, either by accident or intentionally. &lt;br /&gt;· Provide identity on reference. When resolving a reference to an assembly, strong names are used to guarantee the assembly that is loaded came from the expected publisher. &lt;br /&gt;Strong names are implemented using standard public key cryptography. In general, the process works as follows: The author of an assembly generates a key pair (or uses an existing one), signs the file containing the manifest with the private key, and makes the public key available to callers. When references are made to the assembly, the caller records the public key corresponding to the private key used to generate the strong name. &lt;br /&gt;Weak named assemblies are not suitable to be added in GAC and shared. It is essential for an assembly to be strong named.&lt;br /&gt;Strong naming prevents tampering and enables assemblies to be placed in the GAC alongside other assemblies of the same name.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?&lt;/strong&gt; &lt;br /&gt;The hugely simplistic version is that every time it garbage-collects, it starts by assuming everything to be garbage, then goes through and builds a list of everything reachable. Those become not-garbage, everything else doesn't, and gets thrown away. What makes it generational is that every time an object goes through this process and survives, it is noted as being a member of an older generation (up to 2, right now). When the garbage-collector is trying to free memory, it starts with the lowest generation (0) and only works up to higher ones if it can't free up enough space, on the grounds that shorter-lived objects are more likely to have been freed than longer-lived ones.&lt;br /&gt;Non-deterministic finalization implies that the destructor (if any) of an object will not necessarily be run (nor its memory cleaned up, but that's a relatively minor issue) immediately upon its going out of scope. Instead, it will wait until first the garbage collector gets around to finding it, and then the finalisation queue empties down to it; and if the process ends before this happens, it may not be finalised at all. (Although the operating system will usually clean up any process-external resources left open - note the usually there, especially as the exceptions tend to hurt a lot.)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between Finalize() and Dispose()? &lt;/strong&gt;&lt;br /&gt;Dispose() is called by the user of an object to indicate that he is finished with it, enabling that object to release any unmanaged resources it holds. Finalize() is called by the run-time to allow an object which has not had Dispose() called on it to do the same. However, Dispose() operates determinalistically, whereas there is no guarantee that Finalize() will be called immediately when an object goes out of scope - or indeed at all, if the program ends before that object is GCed - and as such Dispose() is generally preferred.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization? &lt;/strong&gt;&lt;br /&gt;The using() pattern is useful because it ensures that Dispose() will always be called when a disposable object (defined as one that implements IDisposable, and thus the Dispose() method) goes out of scope, even if it does so by an exception being thrown, and thus that resources are always released.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does this useful command line do? tasklist /m "mscor*" &lt;/strong&gt;&lt;br /&gt;Lists all the applications and associated tasks/process currently  running on the system with a module whose name begins "mscor" loaded into them; which in nearly all cases means "all the .NET processes".&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What’s wrong with a line like this? DateTime.Parse(myString); &lt;/strong&gt;&lt;br /&gt;Therez nothing wrong with this declaration.Converts the specified string representation of a date and time to its DateTime equivalent.But If the string is not a valid DateTime,It throws an exception.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are PDBs? Where must they be located for debugging to work? &lt;/strong&gt;&lt;br /&gt;A program database (PDB) files holds debugging and project state information that allows incremental linking of debug configuration of your program.There are several different types of symbolic debugging information. The default type for Microsoft compiler is the so-called PDB file. The compiler setting for creating this file is /Zi, or /ZI for C/C++(which creates a PDB file with additional information that enables a feature called ""Edit and Continue"") or a Visual Basic/C#/JScript .NET program with /debug.&lt;br /&gt;A PDB file is a separate file, placed by default in the Debug project subdirectory, that has the same name as the executable file with the extension .pdb. Note that the Visual C++ compiler by default creates an additional PDB file called VC60.pdb for VisulaC++6.0 and VC70.PDB file for VisulaC++7.0. The compiler creates this file during compilation of the source code, when the compiler isn't aware of the final name of the executable. The linker can merge this temporary PDB file into the main one if you tell it to, but it won't do it by default. The PDB file can be useful to display the detailed stack trace with source files and line numbers.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is FullTrust? Do GAC’ed assemblies have FullTrust? &lt;/strong&gt;&lt;br /&gt;Before the .NET Framework existed, Windows had two levels of trust for downloaded code. This old model was a binary trust model. You only had two choices: Full Trust, and No Trust. The code could either do anything you could do, or it wouldn't run at all.&lt;br /&gt; &lt;br /&gt;The permission sets in .NET include FullTrust, SkipVerification, Execution, Nothing, LocalIntranet, Internet and Everything. Full Trust Grants unrestricted permissions to system resources. Fully trusted code run by a normal, nonprivileged user cannot do administrative tasks, but can access any resources the user can access, and do anything the user can do. From a security standpoint, you can think of fully trusted code as being similar to native, unmanaged code, like a traditional ActiveX control.&lt;br /&gt;GAC assemblies are granted FullTrust. In v1.0 and 1.1, the fact that assemblies in the GAC seem to always get a FullTrust grant is actually a side effect of the fact that the GAC lives on the local machine.  If anyone were to lock down the security policy by changing the grant set of the local machine to something less than FullTrust, and if your assembly did not get extra permission from some other code group, it would no longer have FullTrust even though it lives in the GAC.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does this do? gacutil /l | find /i "Corillian" &lt;/strong&gt;&lt;br /&gt;The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache.The tool comes with various optional params to do that.&lt;br /&gt;""/l"" option Lists the contents of the global assembly cache. If you specify the assemblyName parameter(/l [assemblyName]), the tool lists only the assemblies matching that name.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does this do .. sn -t foo.dll ?&lt;/strong&gt;&lt;br /&gt;Sn -t option displays the token for the public key stored in infile. The contents of infile must be previously generated using -p. &lt;br /&gt;Sn.exe computes the token using a hash function from the public key. To save space, the common language runtime stores public key tokens in the manifest as part of a reference to another assembly when it records a dependency to an assembly that has a strong name. The -tp option displays the public key in addition to the token.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do you generate a strong name?&lt;/strong&gt;&lt;br /&gt;.NET provides an utility called strong name tool. You can run this toolfrom the VS.NET command prompt to generate a strong name with an option "-k" and providing the strong key file name. i.e. sn- -k &lt; file-name &gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not? &lt;/strong&gt;&lt;br /&gt;The Debug build is the program compiled with full symbolic debug information and no optimization. The Release build is the program compiled employing  optimization and contains no symbolic debug information. These settings can be changed as per need from Project Configuration properties. The release runs faster since it does not have any debug symbols and is optimized.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explain the use of virtual, sealed, override, and abstract.&lt;/strong&gt; &lt;br /&gt;Abstract: The keyword can be applied for a class or method.&lt;br /&gt;1. Class: If we use abstract keyword for a class it makes the&lt;br /&gt;class an abstract class, which means it cant be instantiated. Though&lt;br /&gt;it is not nessacary to make all the method within the  abstract class to be virtual. ie, Abstract class can have concrete methods&lt;br /&gt;2. Method: If we make a method as abstract, we dont need to provide implementation&lt;br /&gt;of the method in the class but the derived class need to implement/override this method.&lt;br /&gt; &lt;br /&gt;Sealed: It can be applied on a class and methods. It stops the type from further derivation i.e no one can derive class from a sealed class,ie A sealed class cannot be inherited.A sealed class cannot be a abstract class.A compile time error is thrown if you try to specify sealed class as a  base class.&lt;br /&gt;When an instance method declaration includes a sealed modifier, that method is said to be a sealed method. If an instance method declaration includes the sealed modifier, it must also include the override modifier. Use of the sealed modifier prevents a derived class from further overriding the method  For Egs: sealed override public void Sample() { Console.WriteLine("Sealed Method"); }&lt;br /&gt;Virtual &amp; Override: Virtual &amp; Override keywords provides runtime polymorphism. A base class can make some of its methods as virtual which allows the derived class a chance to override the base class implementation by using override keyword.&lt;br /&gt; &lt;br /&gt;For e.g. class Shape&lt;br /&gt;  {&lt;br /&gt;  int a&lt;br /&gt;  public virtual void Display()&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Shape");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; class Rectangle:Shape&lt;br /&gt; {&lt;br /&gt;  public override void Display()&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Derived");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explain the importance and use of each, Version, Culture and PublicKeyToken for an assembly. &lt;/strong&gt;&lt;br /&gt;This three alongwith name of the assembly provide a strong name or fully qualified name to the assembly. When a assebly is referenced with all three.&lt;br /&gt;PublicKeyToken: Each assembly can have a public key embedded in its manifest that identifies the developer. This ensures that once the assembly ships, no one can modify the code or other resources contained in the assembly. &lt;br /&gt; &lt;br /&gt;Culture: Specifies which culture the assembly supports&lt;br /&gt; &lt;br /&gt;Version: The version number of the assembly.It is of the following form major.minor.build.revision.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explain the differences between public, protected, private and internal. ?&lt;/strong&gt;&lt;br /&gt;These all are access modifier and they governs the access level. They can be applied to class, methods, fields.&lt;br /&gt; &lt;br /&gt;Public: Allows class, methods, fields to be accessible from anywhere i.e. within and outside an assembly.&lt;br /&gt;Private: When applied to field and method allows to be accessible within a class.&lt;br /&gt;Protected: Similar to private but can be accessed by members of derived class also.&lt;br /&gt;Internal: They are public within the assembly i.e. they can be accessed by anyone within an assembly but outside assembly they are not visible.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between typeof(foo) and myFoo.GetType()? &lt;/strong&gt;&lt;br /&gt;Typeof is operator which applied to a object returns System.Type object. Typeof cannot be overloaded white GetType has lot of overloads.GetType is a method which also returns System.Type of an object. GetType is used to get the runtime type of the object.&lt;br /&gt;Example from MSDN showing Gettype used to retrive type at untime:-&lt;br /&gt;public class MyBaseClass: Object {&lt;br /&gt;}&lt;br /&gt;public class MyDerivedClass: MyBaseClass {&lt;br /&gt;}&lt;br /&gt;public class Test {&lt;br /&gt; public static void Main() {&lt;br /&gt;     MyBaseClass myBase = new MyBaseClass();&lt;br /&gt;     MyDerivedClass myDerived = new MyDerivedClass();&lt;br /&gt;     object o = myDerived;&lt;br /&gt;      MyBaseClass b = myDerived;&lt;br /&gt;      Console.WriteLine("mybase: Type is {0}", myBase.GetType());&lt;br /&gt;      Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());&lt;br /&gt;      Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());&lt;br /&gt;      Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;/*This code produces the following output.&lt;br /&gt;mybase: Type is MyBaseClass&lt;br /&gt;myDerived: Type is MyDerivedClass&lt;br /&gt;object o = myDerived: Type is MyDerivedClass&lt;br /&gt;MyBaseClass b = myDerived: Type is MyDerivedClass */&lt;br /&gt;Can "this" be used within a static method?&lt;br /&gt;No 'This' cannot be used in a static method. As only static variables/methods can be used in a static method.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What is the purpose of XML Namespaces? &lt;/strong&gt;&lt;br /&gt;An XML Namespace is a collection of element types and attribute names. It consists of 2 parts &lt;br /&gt;1) The first part is the URI used to identify the namespace&lt;br /&gt;2) The second part is the element type or attribute name itself.&lt;br /&gt;Together they form a unique name. The various purpose of XML Namespace are&lt;br /&gt;1. Combine fragments from different documents without any naming conflicts. (See example below.) &lt;br /&gt;2. Write reusable code modules that can be invoked for specific elements and attributes. Universally unique names guarantee that &lt;br /&gt;such modules are invoked only for the correct elements and attributes. &lt;br /&gt;3. Define elements and attributes that can be reused in other schemas or instance documents without fear of name collisions. For &lt;br /&gt;example, you might use XHTML elements in a parts catalog to provide part descriptions. Or you might use the nil attribute &lt;br /&gt;defined in XML Schemas to indicate a missing value.&lt;br /&gt;&lt; Department &gt;&lt;br /&gt;     &lt; Name &gt;DVS1&lt; /Name &gt;&lt;br /&gt;     &lt; addr:Address xmlns:addr="http://www.tu-darmstadt.de/ito/addresses" &gt;&lt;br /&gt;        &lt; addr:Street &gt;Wilhelminenstr. 7&lt; /addr:Street &gt;&lt;br /&gt;        &lt; addr:City &gt;Darmstadt&lt; /addr:City &gt;&lt;br /&gt;        &lt; addr:State &gt;Hessen&lt; /addr:State &gt;&lt;br /&gt;        &lt; addr:Country &gt;Germany&lt; /addr:Country &gt;&lt;br /&gt;        &lt; addr:PostalCode &gt;D-64285&lt; /addr:PostalCode &gt;&lt;br /&gt;     &lt; /addr:Address &gt;&lt;br /&gt;     &lt; serv:Server xmlns:serv="http://www.tu-darmstadt.de/ito/servers" &gt;&lt;br /&gt;        &lt; serv:Name &gt;OurWebServer&lt; /serv:Name &gt;&lt;br /&gt;        &lt; serv:Address &gt;123.45.67.8&lt; /serv:Address &gt;&lt;br /&gt;     &lt; /serv:Server &gt;&lt;br /&gt;  &lt; /Department &gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is difference between MetaData and Manifest ?&lt;/strong&gt;&lt;br /&gt;Metadata and Manifest forms an integral part of an assembly( dll / exe ) in .net framework . &lt;br /&gt;Out of which Metadata is a mandatory component , which as the name suggests gives the details about various components of IL code viz : Methods , properties , fields , class etc. &lt;br /&gt;Essentially Metadata maintains details in form of tables like Methods Metadata tables , Properties Metadata tables , which maintains the list of given type and other details like access specifier , return type etc.&lt;br /&gt;Now Manifest is a part of metadata only , fully called as “manifest metadata tables” , it contains the details of the references needed by the assembly of any other external assembly / type , it could be a custom assembly or standard System namespace .&lt;br /&gt;Now for an assembly that can independently exists and used in the .Net world both the things ( Metadata with Manifest ) are mandatory , so that it can be fully described assembly and can be ported anywhere without any system dependency . Essentially .Net framework can read all assembly related information from assembly itself at runtime .&lt;br /&gt;But for .Net modules , that can’t be used independently , until they are being packaged as a part of an assembly , they don’t contain Manifest but their complete structure is defined by their respective metadata .&lt;br /&gt;Ultimately .Net modules use Manifest Metadata tables of parent assembly which contain them.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the use of Internal keyword?&lt;/strong&gt;&lt;br /&gt;Internal keyword is one of the access specifier available in .Net framework , that makes a type visible in a  given assembly , for e.g : a single dll can contain multiple modules , essentially a multi file assembly , but it forms a single binary component , so any type with internal keyword will be visible throughout the assembly and can be used in any of the modules .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What actually happes when you add a something to arraylistcollection ?&lt;/strong&gt;&lt;br /&gt;Following things will happen :&lt;br /&gt;Arraylist is a dynamic array class in c# in System.Collections namespace derived from interfaces – ICollection , IList , ICloneable , IConvertible  . It terms of in memory structure following is the implementation .&lt;br /&gt;a. Check up the total space if there’s any free space on the declared list .&lt;br /&gt;b. If yes add the new item and increase count by 1 .&lt;br /&gt;c. If No Copy the whole thing to a temporary Array of Last Max. Size .&lt;br /&gt;d. Create new Array with size ( Last Array Size + Increase Value )&lt;br /&gt;e. Copy back values from temp and reference this new array as original array .&lt;br /&gt;f. Must doing Method updates too , need to check it up .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Boxing and unboxing? Does it occure automaatically or u need to write code to box and unbox?&lt;/strong&gt;&lt;br /&gt;Boxing – Process of converting a System.ValueType to Reference Type , Mostly base class System.Object type and allocating it memory on Heap .Reverse is unboxing , but can only be done with prior boxed variables.&lt;br /&gt;Boxing is always implicit but Unboxing needs to be explicitly done via casting , thus ensuring the value type contained inside .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How Boxing and unboxing occures in memory?&lt;/strong&gt;&lt;br /&gt;Boxing converts value type to reference type , thus allocating memory on Heap . Unboxing converts already boxed reference types to value types through explicit casting , thus  allocating memory on stack .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why only boxed types can be unboxed?&lt;/strong&gt;&lt;br /&gt;Unboxing is the process of converting a Reference type variable to Value type and thus allocating memory on the stack . It happens only to those Reference type variables that have been earlier created by Boxing of a Value Type , therefore internally they contain a value type , which can be obtained through explicit casting . For any other Reference type , they don’t internally contain a Value type to Unboxed via explicit casting . This is why only boxed types can be unboxed.&lt;br /&gt;&lt;br /&gt;*********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ASP.NET Interview Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;inetinfo.exe&lt;/strong&gt; is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter &lt;strong&gt;aspnet_isapi.dll&lt;/strong&gt; takes care of it by passing the request tothe actual worker process &lt;strong&gt;aspnet_wp.exe&lt;/strong&gt;.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;2.What’s the difference between Response.Write() and Response.Output.Write()?&lt;/strong&gt;&lt;br /&gt;Response.Output.Write() allows you to write formatted output. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What methods are fired during the page load?&lt;/strong&gt;&lt;br /&gt;Init() - when the page is instantiated&lt;br /&gt;Load() - when the page is loaded into server memory&lt;br /&gt;PreRender() - the brief moment before the page is displayed to the user as HTML&lt;br /&gt;Unload() - when page finishes loading. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.When during the page processing cycle is ViewState available?&lt;/strong&gt;&lt;br /&gt;After the Init() and before the Page_Load(), or OnLoad() for a control. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What namespace does the Web page belong in the .NET Framework class hierarchy?&lt;/strong&gt;&lt;br /&gt;System.Web.UI.Page &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.Where do you store the information about the user’s locale?&lt;/strong&gt;&lt;br /&gt;System.Web.UI.Page.Culture &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?&lt;/strong&gt;&lt;br /&gt;CodeBehind is relevant to Visual Studio.NET only. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.What’s a bubbled event?&lt;/strong&gt;&lt;br /&gt;When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;9.Suppose you want a certain ASP.NET function executed on MouseOver for a certain button.  Where do you add an event handler?&lt;/strong&gt;&lt;br /&gt;Add an OnMouseOver attribute to the button.  Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();"); &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;10.What data types do the RangeValidator control support?&lt;/strong&gt;&lt;br /&gt;Integer, String, and Date. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;11.Explain the differences between Server-side and Client-side code?&lt;/strong&gt;&lt;br /&gt;Server-side code executes on the server.  Client-side code executes in the client's browser. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;12.What type of code (server or client) is found in a Code-Behind class?&lt;/strong&gt;&lt;br /&gt;The answer is server-side code since code-behind is executed on the server.  However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser.  But just to be clear, code-behind executes on the server, thus making it server-side code. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;13.Should user input data validation occur server-side or client-side?  Why?&lt;/strong&gt;&lt;br /&gt;All user input data validation should occur on the server at a minimum.  Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;14.What is the difference between Server.Transfer and Response.Redirect?  Why would I choose one over the other?&lt;/strong&gt;&lt;br /&gt;Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser.  This provides a faster response with a little less overhead on the server.  Server.Transfer does not update the clients url history list or current url.  Response.Redirect is used to redirect the user's browser to another page or site.  This performas a trip back to the client where the client's browser is redirected to the new page.  The user's browser history list is updated to reflect the new address. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;15.Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?&lt;/strong&gt;&lt;br /&gt;Valid answers are:&lt;br /&gt;·  A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.&lt;br /&gt;·  A DataSet is designed to work without any continuing connection to the original data source.&lt;br /&gt;·  Data in a DataSet is bulk-loaded, rather than being loaded on demand.&lt;br /&gt;·  There's no concept of cursor types in a DataSet.&lt;br /&gt;·  DataSets have no current record pointer You can use For Each loops to move through the data.&lt;br /&gt;·  You can store many edits in a DataSet, and write them to the original data source in a single operation.&lt;br /&gt;·  Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;16.What is the Global.asax used for?&lt;/strong&gt;&lt;br /&gt;The Global.asax (including the Global.asax.cs file) is used to implement application and session level events. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;17.What are the Application_Start and Session_Start subroutines used for?&lt;/strong&gt;&lt;br /&gt;This is where you can set the specific variables for the Application and Session objects. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;18.Can you explain what inheritance is and an example of when you might use it?&lt;/strong&gt;&lt;br /&gt;When you want to inherit (use the functionality of) another class.  Example: With a base class named Employee, a Manager class could be derived from the Employee base class. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;19.Whats an assembly?&lt;/strong&gt;&lt;br /&gt;Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;20.Describe the difference between inline and code behind.&lt;/strong&gt;&lt;br /&gt;Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;21.Explain what a diffgram is, and a good use for one?&lt;/strong&gt;&lt;br /&gt;The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML.  A good use is reading database data to an XML file to be sent to a Web Service. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;22.Whats MSIL, and why should my developers need an appreciation of it if at all?&lt;/strong&gt;&lt;br /&gt;MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.  MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;23.Which method do you invoke on the DataAdapter control to load your generated dataset with data?&lt;/strong&gt;&lt;br /&gt;The Fill() method. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;24.Can you edit data in the Repeater control?&lt;/strong&gt;&lt;br /&gt;No, it just reads the information from its data source. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;25.Which template must you provide, in order to display data in a Repeater control?&lt;/strong&gt;&lt;br /&gt;ItemTemplate. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;26.How can you provide an alternating color scheme in a Repeater control?&lt;/strong&gt;&lt;br /&gt;Use the AlternatingItemTemplate. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;27.What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?&lt;/strong&gt;&lt;br /&gt;You must set the DataSource property and call the DataBind method. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;28.What base class do all Web Forms inherit from?&lt;/strong&gt;&lt;br /&gt;The Page class. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;29.Name two properties common in every validation control?&lt;/strong&gt;&lt;br /&gt;ControlToValidate property and Text property. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;30.Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?&lt;/strong&gt;&lt;br /&gt;DataTextField property. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;31.Which control would you use if you needed to make sure the values in two different controls matched?&lt;/strong&gt;&lt;br /&gt;CompareValidator control. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;32.How many classes can a single .NET DLL contain?&lt;/strong&gt;&lt;br /&gt;It can contain many classes.&lt;br /&gt;&lt;br /&gt;*************************************************************************************&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Web Service Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What is the transport protocol you use to call a Web service?&lt;/strong&gt;&lt;br /&gt;SOAP (Simple Object Access Protocol) is the preferred protocol. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.True or False: A Web service can only be written in .NET?&lt;/strong&gt;&lt;br /&gt;False &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What does WSDL stand for?&lt;/strong&gt;&lt;br /&gt;Web Services Description Language. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.Where on the Internet would you look for Web services?&lt;/strong&gt;&lt;br /&gt;http://www.uddi.org &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.True or False: To test a Web service you must create a Windows application or Web application to consume this service?&lt;/strong&gt;&lt;br /&gt;False, the web service comes with a test page and it provides HTTP-GET method to test.&lt;br /&gt;&lt;br /&gt;************************************************************************************&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;State Management Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What is ViewState?&lt;/strong&gt;&lt;br /&gt;ViewState allows the state of objects (serializable) to be stored in a hidden field on the page.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.  ViewState is used the retain the state of server-side objects between postabacks. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What is the lifespan for items stored in ViewState?&lt;/strong&gt;&lt;br /&gt;Item stored in ViewState exist for the life of the current page.  This includes postbacks (to the same page). &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What does the "EnableViewState" property do?  Why would I want it on or off?&lt;/strong&gt;&lt;br /&gt;It allows the page to save the users input on a form across postbacks.  It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser.  When the page is posted back to the server the server control is recreated with the state stored in viewstate. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.What are the different types of Session state management options available with ASP.NET?&lt;/strong&gt;&lt;br /&gt;ASP.NET provides In-Process and Out-of-Process state management.  In-Process stores the session in memory on the web server.  This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server.  Out-of-Process Session state management stores data in an external data source.  The external data source may be either a SQL Server or a State Server service.  Out-of-Process state management requires that all objects stored in session are serializable.&lt;br /&gt;&lt;br /&gt;************************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Remoting Interview Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What’s a Windows process?&lt;/strong&gt;&lt;br /&gt;It’s an application that’s running and had been allocated memory. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What’s typical about a Windows process in regards to memory allocation?&lt;/strong&gt;&lt;br /&gt;Each process is allocated its own block of available RAM space, no process can access another process’ code or data. If the process crashes, it dies alone without taking the entire OS or a bunch of other applications down. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.Explain what relationship is between a Process, Application Domain, and Application?&lt;/strong&gt;&lt;br /&gt;A process is an instance of a running application. An application is an executable on the hard drive or network. There can be numerous processes launched of the same application (5 copies of Word running), but 1 process can run just 1 application. &lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;4.What are possible implementations of distributed applications in .NET?&lt;/strong&gt;&lt;br /&gt;.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What are the consideration in deciding to use .NET Remoting or ASP.NET Web Services?&lt;/strong&gt;&lt;br /&gt;Remoting is a more efficient communication exchange when you can control both ends of the application involved in the communication process.  Web Services provide an open-protocol-based exchange of informaion.  Web Services are best when you need to communicate with an external organization or another (non-.NET) technology.&lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;6.What’s a proxy of the server object in .NET Remoting?&lt;/strong&gt;&lt;br /&gt;It’s a fake copy of the server object that resides on the client side and behaves as if it was the server. It handles the communication between real server object and the client object. This process is also known as marshaling. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.What are remotable objects in .NET Remoting?&lt;/strong&gt;&lt;br /&gt;Remotable objects are the objects that can be marshaled across the application domains. You can marshal by value, where a deep copy of the object is created and then passed to the receiver. You can also marshal by reference, where just a reference to an existing object is passed. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.What are channels in .NET Remoting?&lt;/strong&gt;&lt;br /&gt;Channels represent the objects that transfer the other serialized objects from one application domain to another and from one computer to another, as well as one process to another on the same box. A channel must exist before an object can be transferred. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;9.What security measures exist for .NET Remoting in System.Runtime.Remoting?&lt;/strong&gt;&lt;br /&gt;None. Security should be taken care of at the application level. Cryptography and other security techniques can be applied at application or server level. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;10.What is a formatter?&lt;/strong&gt;&lt;br /&gt;A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;11.Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?&lt;/strong&gt;&lt;br /&gt;Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperable. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;12.What’s SingleCall activation mode used for?&lt;/strong&gt;&lt;br /&gt;If the server object is instantiated for responding to just one single request, the request should be made in SingleCall mode. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;13.What’s Singleton activation mode?&lt;/strong&gt;&lt;br /&gt;A single object is instantiated regardless of the number of clients accessing it. Lifetime of this object is determined by lifetime lease. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;14.How do you define the lease of the object?&lt;/strong&gt;&lt;br /&gt;By implementing ILease interface when writing the class code. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;15.Can you configure a .NET Remoting object via XML file?&lt;/strong&gt;&lt;br /&gt;Yes, via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;16.How can you automatically generate interface for the remotable object in .NET with Microsoft tools?&lt;/strong&gt;&lt;br /&gt;Use the Soapsuds tool.&lt;br /&gt;&lt;br /&gt;*************************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;C# Interview Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.Does C# support multiple-inheritance? &lt;/strong&gt;&lt;br /&gt;No.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.Who is a protected class-level variable available to? &lt;/strong&gt;&lt;br /&gt;It is available to any sub-class (a class inheriting this class).&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.Are private class-level variables inherited? &lt;/strong&gt;&lt;br /&gt;Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.Describe the accessibility modifier “protected internal”. &lt;/strong&gt;&lt;br /&gt;It is available to classes that are within the same assembly and derived from the specified base class. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What’s the top .NET class that everything is derived from? &lt;/strong&gt;&lt;br /&gt;System.Object. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.What does the term immutable mean?&lt;/strong&gt;&lt;br /&gt;The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.What’s the difference between System.String and System.Text.StringBuilder classes?&lt;/strong&gt;&lt;br /&gt;System.String is immutable.  System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.What’s the advantage of using System.Text.StringBuilder over System.String?&lt;/strong&gt;&lt;br /&gt;StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;9.Can you store multiple data types in System.Array?&lt;/strong&gt;&lt;br /&gt;No. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;10.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?&lt;/strong&gt;&lt;br /&gt;The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;11.How can you sort the elements of the array in descending order?&lt;/strong&gt;&lt;br /&gt;By calling Sort() and then Reverse() methods. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;12.What’s the .NET collection class that allows an element to be accessed using a unique key?&lt;/strong&gt;&lt;br /&gt;HashTable. &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;13.What class is underneath the SortedList class?&lt;/strong&gt;A sorted HashTable. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;14.Will the finally block get executed if an exception has not occurred?­&lt;/strong&gt;&lt;br /&gt;Yes. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;15.What’s the C# syntax to catch any possible exception?&lt;/strong&gt;&lt;br /&gt;A catch block that catches the exception of type System.Exception.  You can also omit the parameter data type in this case and just write catch {}. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;16.Can multiple catch blocks be executed for a single try statement?&lt;/strong&gt;&lt;br /&gt;No.  Once the proper catch block processed, control is transferred to the finally block (if there are any). &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;17.Explain the three services model commonly know as a three-tier application.&lt;/strong&gt;&lt;br /&gt;Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources). &lt;br /&gt;&lt;br /&gt;************************************************************************************&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;Class Questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What is the syntax to inherit from a class in C#? &lt;/strong&gt;&lt;br /&gt;Place a colon and then the name of the base class.&lt;br /&gt;Example: class MyNewClass : MyBaseClass &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.Can you prevent your class from being inherited by another class? &lt;/strong&gt;&lt;br /&gt;Yes.  The keyword “sealed” will prevent the class from being inherited. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.Can you allow a class to be inherited, but prevent the method from being over-ridden?&lt;/strong&gt;&lt;br /&gt;Yes.  Just leave the class public and make the method sealed. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.What’s an abstract class?&lt;/strong&gt;&lt;br /&gt;A class that cannot be instantiated.  An abstract class is a class that must be inherited and have the methods overridden.  An abstract class is essentially a blueprint for a class without any implementation. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.When do you absolutely have to declare a class as abstract?&lt;/strong&gt;&lt;br /&gt;1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden. &lt;br /&gt;2.  When at least one of the methods in the class is abstract. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.What is an interface class?&lt;/strong&gt;&lt;br /&gt;Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.Why can’t you specify the accessibility modifier for methods inside the interface?&lt;/strong&gt;&lt;br /&gt;They all must be public, and are therefore public by default. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.Can you inherit multiple interfaces?&lt;/strong&gt;&lt;br /&gt;Yes.  .NET does support multiple interfaces. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;9.What happens if you inherit multiple interfaces and they have conflicting method names?&lt;/strong&gt;&lt;br /&gt;It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay. &lt;br /&gt;To Do: Investigate &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;10.What’s the difference between an interface and abstract class?&lt;/strong&gt;&lt;br /&gt;In an interface class, all methods are abstract - there is no implementation.  In an abstract class some methods can be concrete.  In an interface class, no accessibility modifiers are allowed.  An abstract class may have accessibility modifiers. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;11.What is the difference between a Struct and a Class?&lt;/strong&gt;&lt;br /&gt;Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval.  Another difference is that structs cannot inherit. &lt;br /&gt;  &lt;br /&gt;***********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Method and Property Questions &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What’s the implicit name of the parameter that gets passed into the set method/property of a class? &lt;/strong&gt;&lt;br /&gt;Value.  The data type of the value parameter is defined by whatever data type the property is declared as. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What does the keyword “virtual” declare for a method or property? &lt;/strong&gt;&lt;br /&gt;The method or property can be overridden. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.How is method overriding different from method overloading? &lt;/strong&gt;&lt;br /&gt;When overriding a method, you change the behavior of the method for the derived class.  Overloading a method simply involves having another method with the same name within the class. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.Can you declare an override method to be static if the original method is not static? &lt;/strong&gt;&lt;br /&gt;No.  The signature of the virtual method must remain the same.  (Note: Only the keyword virtual is changed to keyword override) &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What are the different ways a method can be overloaded? &lt;/strong&gt;&lt;br /&gt;Different parameter data types, different number of parameters, different order of parameters. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?&lt;/strong&gt;&lt;br /&gt;Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.&lt;br /&gt;&lt;br /&gt;************************************************************************************&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Events and Delegates&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What’s a delegate? &lt;/strong&gt;&lt;br /&gt;A delegate object encapsulates a reference to a method. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What’s a multicast delegate? &lt;/strong&gt;&lt;br /&gt;A delegate that has multiple handlers assigned to it.  Each assigned handler (method) is called.&lt;br /&gt; &lt;br /&gt;***********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Documentation Questions &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.Is XML case-sensitive? &lt;/strong&gt;&lt;br /&gt;Yes. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What’s the difference between // comments, /* */ comments and /// comments? &lt;/strong&gt;&lt;br /&gt;Single-line comments, multi-line comments, and XML documentation comments. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.How do you generate documentation from the C# file commented properly with a command-line compiler? &lt;/strong&gt;&lt;br /&gt;Compile it with the /doc switch.&lt;br /&gt; &lt;br /&gt;************************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Debugging and Testing Questions &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What debugging tools come with the .NET SDK?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;1.   CorDBG&lt;/strong&gt; – command-line debugger.  To use CorDbg, you must compile the original C# file using the /debug switch. &lt;br /&gt;&lt;strong&gt;2.   DbgCLR&lt;/strong&gt; – graphic debugger.  Visual Studio .NET uses the DbgCLR. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What does assert() method do? &lt;/strong&gt;&lt;br /&gt;In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false.  The program proceeds without any interruption if the condition is true. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What’s the difference between the Debug class and Trace class? &lt;/strong&gt;&lt;br /&gt;Documentation looks the same.  Use Debug class for debug builds, use Trace class for both debug and release builds. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.Why are there five tracing levels in System.Diagnostics.TraceSwitcher? &lt;/strong&gt;&lt;br /&gt;The tracing dumps can be quite verbose.  For applications that are constantly running you run the risk of overloading the machine and the hard drive.  Five levels range from None to Verbose, allowing you to fine-tune the tracing activities. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.Where is the output of TextWriterTraceListener redirected? &lt;/strong&gt;&lt;br /&gt;To the Console or a text file depending on the parameter passed to the constructor. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.How do you debug an ASP.NET Web application? &lt;/strong&gt;&lt;br /&gt;Attach the aspnet_wp.exe process to the DbgClr debugger. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.What are three test cases you should go through in unit testing? &lt;/strong&gt;&lt;br /&gt;1.       Positive test cases (correct data, correct output).&lt;br /&gt;2.       Negative test cases (broken or missing data, proper handling).&lt;br /&gt;3.       Exception test cases (exceptions are thrown and caught properly). &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.Can you change the value of a variable while debugging a C# application? &lt;/strong&gt;&lt;br /&gt;Yes.  If you are debugging via Visual Studio.NET, just go to Immediate window. &lt;br /&gt;&lt;br /&gt;***********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ADO.NET and Database Questions &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What is the role of the DataReader class in ADO.NET connections? &lt;/strong&gt;&lt;br /&gt;It returns a read-only, forward-only rowset from the data source.  A DataReader provides fast access when a forward-only sequential read is needed. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? &lt;/strong&gt;&lt;br /&gt;SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix.  OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What is the wildcard character in SQL? &lt;/strong&gt;&lt;br /&gt;Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.Explain ACID rule of thumb for transactions.&lt;/strong&gt;&lt;br /&gt;A transaction must be:&lt;br /&gt;1.       &lt;strong&gt;Atomic&lt;/strong&gt; - it is one unit of work and does not dependent on previous and following transactions.&lt;br /&gt;2.       &lt;strong&gt;Consistent&lt;/strong&gt; - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.&lt;br /&gt;3.       &lt;strong&gt;Isolated&lt;/strong&gt; - no transaction sees the intermediate results of the current transaction).&lt;br /&gt;4.       &lt;strong&gt;Durable&lt;/strong&gt; - the values persist if the data had been committed even if the system crashes right after. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What connections does Microsoft SQL Server support? &lt;/strong&gt;&lt;br /&gt;Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password). &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted? &lt;/strong&gt;&lt;br /&gt;Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.What does the Initial Catalog parameter define in the connection string? &lt;/strong&gt;&lt;br /&gt;The database name to connect to. &lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;8.What does the Dispose method do with the connection object? &lt;/strong&gt;&lt;br /&gt;Deletes it from the memory.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;9.What is a pre-requisite for connection pooling? &lt;/strong&gt;&lt;br /&gt;Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.  The connection string must be identical.&lt;br /&gt;&lt;br /&gt;*********************************************************************************&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Assembly Questions &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.How is the DLL Hell problem solved in .NET? &lt;/strong&gt;&lt;br /&gt;Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;2.What are the ways to deploy an assembly? &lt;/strong&gt;&lt;br /&gt;An MSI installer, a CAB archive, and XCOPY command. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;3.What is a satellite assembly? &lt;/strong&gt;&lt;br /&gt;When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;4.What namespaces are necessary to create a localized application? &lt;/strong&gt;&lt;br /&gt;System.Globalization and System.Resources.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;5.What is the smallest unit of execution in .NET?&lt;/strong&gt;&lt;br /&gt;an Assembly.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;6.When should you call the garbage collector in .NET?&lt;/strong&gt;&lt;br /&gt;As a good rule, you should not call the garbage collector.  However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory.  However, this is usually not a good practice.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;7.How do you convert a value-type to a reference-type?&lt;/strong&gt;&lt;br /&gt;Use Boxing.&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;8.What happens in memory when you Box and Unbox a value-type?&lt;/strong&gt;&lt;br /&gt;Boxing converts a value-type to a reference-type, thus storing the object on the heap.  Unboxing converts a reference-type to a value-type, thus storing the value on the stack.&lt;br /&gt;&lt;br /&gt;**********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ASP.NET DataGrid questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What is datagrid?&lt;/strong&gt;&lt;br /&gt; The DataGrid Web server control is a powerful tool for displaying information from a data source. It is easy to use; you can display editable data in a professional-looking grid by setting only a few properties. At the same time, the grid has a sophisticated object model that provides you with great flexibility in how you display the data. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2.What’s the difference between the System.Web.UI.WebControls.DataGrid and and System.Windows.Forms.DataGrid?&lt;/strong&gt;&lt;br /&gt; The Web UI control does not inherently support master-detail data structures. As with other Web server controls, it does not support two-way data binding. If you want to update data, you must write code to do this yourself. You can only edit one row at a time. It does not inherently support sorting, although it raises events you can handle in order to sort the grid contents. You can bind the Web Forms DataGrid to any object that supports the IEnumerable interface. The Web Forms DataGrid control supports paging. It is easy to customize the appearance and layout of the Web Forms DataGrid control as compared to the Windows Forms one. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3.How do you customize the column content inside the datagrid?&lt;/strong&gt;&lt;br /&gt; If you want to customize the content of a column, make the column a template column. Template columns work like item templates in the DataList or Repeater control, except that you are defining the layout of a column rather than a row.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.How do you apply specific formatting to the data inside the cells?&lt;/strong&gt;&lt;br /&gt; You cannot specify formatting for columns generated when the grid’s AutoGenerateColumns property is set to true, only for bound or template columns. To format, set the column’s DataFormatString property to a string-formatting expression suitable for the data type of the data you are formatting. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5.How do you hide the columns?&lt;/strong&gt;&lt;br /&gt; One way to have columns appear dynamically is to create them at design time, and then to hide or show them as needed. You can do this by setting a column’s Visible property. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;6.How do you display an editable drop-down list? &lt;/strong&gt;&lt;br /&gt;Displaying a drop-down list requires a template column in the grid. Typically, the ItemTemplate contains a control such as a data-bound Label control to show the current value of a field in the record. You then add a drop-down list to the EditItemTemplate. In Visual Studio, you can add a template column in the Property builder for the grid, and then use standard template editing to remove the default TextBox control from the EditItemTemplate and drag a DropDownList control into it instead. Alternatively, you can add the template column in HTML view. After you have created the template column with the drop-down list in it, there are two tasks. The first is to populate the list. The second is to preselect the appropriate item in the list — for example, if a book’s genre is set to “fiction,” when the drop-down list displays, you often want “fiction” to be preselected. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;7.How do you check whether the row data has been changed?&lt;/strong&gt;&lt;br /&gt; The definitive way to determine whether a row has been dirtied is to handle the changed event for the controls in a row. For example, if your grid row contains a TextBox control, you can respond to the control’s TextChanged event. Similarly, for check boxes, you can respond to a CheckedChanged event. In the handler for these events, you maintain a list of the rows to be updated. Generally, the best strategy is to track the primary keys of the affected rows. For example, you can maintain an ArrayList object that contains the primary keys of the rows to update. &lt;br /&gt;&lt;br /&gt;*********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Windows code security questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What’s the difference between code-based security and role-based security? &lt;br /&gt;Which one is better?&lt;/strong&gt;&lt;br /&gt;Code security is the approach of using permissions and permission sets for a given code to run. The admin, for example, can disable running executables off the Internet or restrict access to corporate database to only few applications. Role-based security most of the time involves the code running with the privileges of the current user. This way the code cannot supposedly do more harm than mess up a single user account. There’s no better, or 100% thumbs-up approach, depending on the nature of deployment, both code-based and role-based security could be implemented to an extent. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2.How can you work with permissions from your .NET application? &lt;/strong&gt;&lt;br /&gt;You can request permission to do something and you can demand certain permissions from other apps. You can also refuse permissions so that your app is not inadvertently used to destroy some data.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;3.How can C# app request minimum permissions?&lt;/strong&gt;&lt;br /&gt;using System.Security.Permissions;&lt;br /&gt;[assembly:FileDialogPermissionAttribute(SecurityAction.RequestMinimum, Unrestricted=true)] &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.What’s a code group?&lt;/strong&gt;&lt;br /&gt; A code group is a set of assemblies that share a security context.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5.What’s the difference between authentication and authorization?&lt;/strong&gt;&lt;br /&gt; Authentication happens first. You verify user’s identity based on credentials. Authorization is making sure the user only gets access to the resources he has credentials for. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;6.What are the authentication modes in ASP.NET?&lt;/strong&gt;&lt;br /&gt; None, Windows, Forms and Passport.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;7.Are the actual permissions for the application defined at run-time or compile-time?&lt;/strong&gt;&lt;br /&gt; The CLR computes actual permissions at runtime based on code group membership and the calling chain of the code. &lt;br /&gt;&lt;br /&gt;**********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NET Deployment questions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.What do you know about .NET assemblies?&lt;/strong&gt;&lt;br /&gt; Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET remoting applications. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2.What’s the difference between private and shared assembly?&lt;/strong&gt;&lt;br /&gt; Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3.What’s a strong name?&lt;/strong&gt;&lt;br /&gt; A strong name includes the name of the assembly, version number, culture identity, and a public key token. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.How can you tell the application to look for assemblies at the locations other than its own install?&lt;/strong&gt;&lt;br /&gt; Use the&lt;br /&gt;directive in the XML .config file for a given application.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_xmdzLHNex7Q/SG3EFfrtITI/AAAAAAAAAJ8/1Sqx8XiYS3s/s1600-h/tag.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_xmdzLHNex7Q/SG3EFfrtITI/AAAAAAAAAJ8/1Sqx8XiYS3s/s320/tag.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5219043141875474738" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;should do the trick. Or you can add additional search paths in the Properties box of the deployed application. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5.How can you debug failed assembly binds?&lt;/strong&gt;&lt;br /&gt; Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;6.Where are shared assemblies stored?&lt;/strong&gt;&lt;br /&gt; Global assembly cache.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;7.How can you create a strong name for a .NET assembly?&lt;/strong&gt;&lt;br /&gt; With the help of Strong Name tool (sn.exe). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;8.Where’s global assembly cache located on the system?&lt;/strong&gt;&lt;br /&gt; Usually C:\winnt\assembly or C:\windows\assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;9.Can you have two files with the same file name in GAC?&lt;/strong&gt;&lt;br /&gt; Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;10.So let’s say I have an application that uses MyApp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name MyApp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new MyApp.dll?&lt;/strong&gt;&lt;br /&gt; Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;11.What is delay signing?&lt;/strong&gt;&lt;br /&gt; Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-5091829033281611242?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/5091829033281611242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=5091829033281611242' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/5091829033281611242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/5091829033281611242'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/07/net-interview-faq.html' title='.NET Interview Faq'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_xmdzLHNex7Q/SG3EFfrtITI/AAAAAAAAAJ8/1Sqx8XiYS3s/s72-c/tag.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-7733048437847996945</id><published>2008-07-01T01:55:00.000-07:00</published><updated>2008-12-09T16:00:15.731-08:00</updated><title type='text'>.NET Xml</title><content type='html'>&lt;strong&gt;An Introduction to Working with XML in .NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Working with XML in .NET applications is a fairly straightforward process especially if you've used MSXML3 in the past. Even if you haven't worked with MSXML3 you'll find that using the classes found in the .NET platform is easy once you know more about them.&lt;br /&gt;&lt;br /&gt;There are two main APIs that you can use to access data found within XML documents. These include forward-only, non-cached access, and random access through using the Document Object Model (DOM). The classes that expose both APIs are found within the System.Xml assembly.&lt;br /&gt;&lt;br /&gt;If you want to access data within an XML document in the most fast and efficient way possible then you'll want to use the XmlTextReader class. This class exposes a pull model that has many advantages over the push model found in the Simple API for XML (SAX). To use this class you must reference the System.Xml assembly in your file. In C# you would do this with the "using" keyword while in Visual Basic you would use the "imports" keyword. Once the assembly is referenced, you can then instantiate the reader as shown below:&lt;br /&gt;&lt;br /&gt;    XmlTextReader reader = new XmlTextReader(pathToXmlDoc);&lt;br /&gt;    int elementCount = 0;&lt;br /&gt;    while (reader.Read()) {&lt;br /&gt;        if (reader.NodeType == XmlNodeType.Element) {&lt;br /&gt;            elementCount++;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;There are several different constructors available for the XmlTextReader class. The one shown above accepts an XML document file path as a string argument.&lt;br /&gt;&lt;br /&gt;While the forward-only pull model is certainly very efficient, it is read-only and therefore doesn't allow you to insert, delete, or update nodes in a document. In cases where you need more control or flexibility over an XML document, you'll want to look at using the Document Object Model (DOM). The DOM API works by loading each node found within an XML document into a tree structure similar to a genealogical chart. By having this in-memory structure, random access to different nodes within an XML document is possible. &lt;br /&gt;&lt;br /&gt;To start the process of creating the DOM tree, you need to reference the System.Xml assembly in your file and then instantiate the XmlDocument class:&lt;br /&gt;&lt;br /&gt;    XmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;    xmlDoc.Load(pathToXmlDoc);&lt;br /&gt;    XmlNode root = xmlDoc.DocumentElement;&lt;br /&gt;&lt;br /&gt;Adding nodes to the tree can easily be accomplished by using methods associated with the XmlDocument class. The following example shows how to load XML from a file and then add an element as a child of a root node named "root." It also shows how an attribute can be added to a node as well:&lt;br /&gt;&lt;br /&gt;    XmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;    XmlDoc.Load(pathToXmlDoc);&lt;br /&gt;    XmlElement root = xmlDoc.DocumentElement;&lt;br /&gt;    XmlElement newNode = doc.CreateElement("newNode");&lt;br /&gt;    newNode.SetAttribute("id","1");&lt;br /&gt;    root.AppendChild(newNode);&lt;br /&gt;&lt;br /&gt;This code would result in the following XML document:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoRe6FDM7I/AAAAAAAAAJU/xq_pg9z4EyI/s1600-h/Xml_code1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoRe6FDM7I/AAAAAAAAAJU/xq_pg9z4EyI/s320/Xml_code1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5218002340946326450" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In cases where a string containing XML needs to be loaded into the DOM, the XmlDocument class's LoadXml() method can be used. Once in the DOM, the XML can then be manipulated as shown above:&lt;br /&gt;&lt;br /&gt;    string myXml = "&lt;root&gt;&lt;someNode&gt;Hello&lt;/someNode&gt;&lt;/root&gt;";&lt;br /&gt;    XmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;    xmlDoc.LoadXml(myXml);&lt;br /&gt;    //....manipulation or reading of the nodes can occur here&lt;br /&gt;&lt;br /&gt;There are many other classes that can perform a variety of tasks in the System.Xml assembly. This article has barely scratched the surface but has hopefully shown that much of your experience with MSXML3 can be used in .NET applications as well. Using many of the other XML related classes in the .NET platform will be detailed in future articles so stay tuned!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading XML Files using XmlDocument in VB.NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Suppose I have following XML fragment:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoRgQr2ipI/AAAAAAAAAJc/5WRPC_tacz4/s1600-h/Xml_code2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoRgQr2ipI/AAAAAAAAAJc/5WRPC_tacz4/s320/Xml_code2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5218002364194523794" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; Now, how can I loop through my collection of authors and for each author  retrieve its first and last name and put them in a variable strFirst and  strLast?&lt;br /&gt;&lt;br /&gt; - - - XMLApp.vb&lt;br /&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Xml&lt;br /&gt;&lt;br /&gt;_&lt;br /&gt;Public Class XMLApp&lt;br /&gt;&lt;br /&gt;Public Sub YourMethod(strFirst As [String], strLast As [String])&lt;br /&gt;' Do something with strFirst and strLast.&lt;br /&gt;' ...&lt;br /&gt;Console.WriteLine("{0}, {1}", strLast, strFirst)&lt;br /&gt;End Sub 'YourMethod&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Public Sub ProcessXML(xmlText As [String])&lt;br /&gt;Dim _doc As New XmlDocument()&lt;br /&gt;_doc.LoadXml(xmlText)&lt;br /&gt;' alternately, _doc.Load( _strFilename); to read from a file.&lt;br /&gt;Dim _fnames As XmlNodeList = _doc.GetElementsByTagName("FirstName")&lt;br /&gt;Dim _lnames As XmlNodeList = _doc.GetElementsByTagName("LastName")&lt;br /&gt;&lt;br /&gt;' I'm assuming every FirstName has a LastName in this example, your requirements may vary. // for ( int _i = 0; _i &lt; _fnames.Count; ++_i )&lt;br /&gt;If (True) Then&lt;br /&gt;YourMethod(_fnames(_i).InnerText, _lnames(_i).InnerText)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Dim Main As&lt;br /&gt;&lt;br /&gt;[String]()&lt;br /&gt;If (True) Then&lt;br /&gt;Dim _app As New XMLApp()&lt;br /&gt;' Passing XML text as a String, you can also use the&lt;br /&gt;' XMLDocument::Load( ) method to read the XML from a file.&lt;br /&gt;'&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_xmdzLHNex7Q/SGoRgQPIkiI/AAAAAAAAAJk/jOsO3rE0xPw/s1600-h/Xml_code3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_xmdzLHNex7Q/SGoRgQPIkiI/AAAAAAAAAJk/jOsO3rE0xPw/s320/Xml_code3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5218002364074070562" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;End If '&lt;br /&gt;&lt;br /&gt;End Sub 'ProcessXML&lt;br /&gt;End Class 'XMLApp&lt;br /&gt;&lt;br /&gt;' end XMLApp&lt;br /&gt;&lt;br /&gt;  - - - XMLApp.vb&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Remember to /reference the System.Xml.dll on the command-line  to build XMLApp.vb:&lt;br /&gt; vbc.exe /r:System.Xml.dll XMLApp.vb&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Programming using VB.NET&lt;/strong&gt;&lt;br /&gt;                    &lt;br /&gt;                            XML has been an integral part of programming these days since the world of programming is moving towards the web. XML is one of the most useful easier ways to store and transfer data. Microsoft .NET framework utilizes XML to store data and transfer data between applications and remote systems including local, intranet or on the Internet. &lt;br /&gt;&lt;br /&gt;In this article we will explore XML classes and namespaces of .NET Framework Class Library and how to use them in VB.NET to read, write and navigate XML documents.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Namespaces and Classes&lt;/strong&gt; &lt;br /&gt;Microsoft .NET Runtime Library contains many classes to work with XML documents. These classes are stored in five namespaces - System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.XPath, and System.Xml.Xsl. The purpose of each of these namespace is different. All classes reside in one single assembly System.Xml.dll assembly.&lt;br /&gt;&lt;br /&gt;Before you proceed to use XML classes in your programs, you need to add reference to the System.Xml.dll assembly and use namespaces in your program by using Imports keyword.&lt;br /&gt;&lt;br /&gt;First namespace is System.Xml. This namespace contains major classes. This namespace contains many classes to read and write XML documents. In this article, we are going to concentrate on reader and write class. These reader and writer classes are used to read and write XMl documents. These classes are - XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, and XmlTextWriter. As you can see there are four reader and two writer classes.&lt;br /&gt;&lt;br /&gt;The XmlReader class is an abstract bases classes and contains methods and properties to read a document. The Read method reads a node in the stream. Besides reading functionality, this class also contains methods to navigate through a document nodes. Some of these methods are MoveToAttribute, MoveToFirstAttribute, MoveToContent, MoveToFirstContent, MoveToElement and MoveToNextAttribute. ReadString, ReadInnerXml, ReadOuterXml, and ReadStartElement are more read methods. This class also has a method Skip to skip current node and move to next one. We’ll see these methods in our sample example.&lt;br /&gt;&lt;br /&gt;The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas.&lt;br /&gt;&lt;br /&gt;The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items. This class is base class for XmlTextWriter class, which we’ll be using in our sample example.&lt;br /&gt;&lt;br /&gt;The XmlNode class plays an important role. Although, this class represents a single node of XML but that could be the root node of an XML document and could represent the entire file. This class is an abstract base class for many useful classes for inserting, removing, and replacing nodes, navigating through the document. It also contains properties to get a parent or child, name, last child, node type and more. Three major classes derived from XmlNode are XmlDocument, XmlDataDocument and XmlDocumentFragment. XmlDocument class represents an XML document and provides methods and properties to load and save a document. It also provides functionality to add XML items such as attributes, comments, spaces, elements, and new nodes. The Load and LoadXml methods can be used to load XML documents and Save method to save a document respectively. XmlDocumentFragment class represents a document fragment, which can be used to add to a document. The XmlDataDocument class provides methods and properties to work with ADO.NET data set objects.&lt;br /&gt;&lt;br /&gt;In spite of above discussed classes, System.Xml namespace contains more classes. Few of them are XmlConvert, XmlLinkedNode, and XmlNodeList.&lt;br /&gt;&lt;br /&gt;Next namespace in Xml series is System.Xml.Schema. It classes  to work with XML schemas such XmlSchema, XmlSchemaAll, XmlSchemaXPath, XmlSchemaType.&lt;br /&gt;&lt;br /&gt;The System.Xml.Serialization namespace contains classes that are used to serialize objects into XML format documents or streams.&lt;br /&gt;&lt;br /&gt;The System.Xml.XPath Namespce contains XPath related classes to use XPath specifications. This namespace has following classes  – XPathDocument, XPathExression, XPathNavigator, and XPathNodeIterator.&lt;br /&gt;&lt;br /&gt;With the help of XpathDocument, XpathNavigator provides a fast navigation though XML documents. This class contains many Move methods to move through a document.&lt;br /&gt;The System.Xml.Xsl namespace contains classes to work with XSL/T transformations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading XML Documents&lt;/strong&gt; &lt;br /&gt;In my sample application, I’m using books.xml to read and display its data through XmlTextReader. This file comes with VS.NET samples. You can search this on your machine and change the path of the file in the following line:&lt;br /&gt;&lt;br /&gt;Dim textReader As XmlTextReader = New XmlTextReader("books.xml")  &lt;br /&gt;&lt;br /&gt;Or you can use any XML file.&lt;br /&gt;&lt;br /&gt;The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. Besides XmlReader methods and properties, these classes also contain members to read text, node, and schemas respectively.&lt;br /&gt;&lt;br /&gt;I am using XmlTextReader class to read an XML file. You read a file by passing file name as a parameter in constructor.&lt;br /&gt;&lt;br /&gt;Dim textReader As XmlTextReader = New XmlTextReader("books.xml")&lt;br /&gt;&lt;br /&gt;After creating an instance of XmlTextReader, you call Read method to start reading the document. After read method is called, you can read all information and data stored in a document. XmlReader class has properties such as Name, BaseURI, Depth, LineNumber an so on.&lt;br /&gt;&lt;br /&gt;List 1 reads a document and displays a node information using these properties. &lt;br /&gt;&lt;br /&gt;List 1: Reading an XML document Properties &lt;br /&gt;&lt;br /&gt;' Import System.Xml namespace&lt;br /&gt;Imports System.Xml&lt;br /&gt; &lt;br /&gt;Module Module1&lt;br /&gt; &lt;br /&gt;    Sub Main()&lt;br /&gt; &lt;br /&gt;        ' Create an isntance of XmlTextReader and call Read method to read&lt;br /&gt;the file&lt;br /&gt;        Dim textReader As XmlTextReader = New&lt;br /&gt;XmlTextReader("C:\\books.xml")&lt;br /&gt;        textReader.Read()&lt;br /&gt; &lt;br /&gt;        ' If the node has value&lt;br /&gt;        If textReader.HasValue Then&lt;br /&gt;            ' Move to fist element&lt;br /&gt;            textReader.MoveToElement()&lt;br /&gt;            Console.WriteLine("XmlTextReader Properties Test")&lt;br /&gt;            Console.WriteLine("===================")&lt;br /&gt; &lt;br /&gt;            ' Read this element's properties and display them on console&lt;br /&gt;            Console.WriteLine("Name:" + textReader.Name)&lt;br /&gt;            Console.WriteLine("Base URI:" + textReader.BaseURI)&lt;br /&gt;            Console.WriteLine("Local Name:" + textReader.LocalName)&lt;br /&gt;            Console.WriteLine("Attribute Count:" +textReader.AttributeCount.ToString())&lt;br /&gt;            Console.WriteLine("Depth:" + textReader.Depth.ToString())&lt;br /&gt;            Console.WriteLine("Line Number:" +&lt;br /&gt;textReader.LineNumber.ToString())&lt;br /&gt;            Console.WriteLine("Node Type:" +&lt;br /&gt;textReader.NodeType.ToString())&lt;br /&gt;            Console.WriteLine("Attribute Count:" +&lt;br /&gt;textReader.Value.ToString())&lt;br /&gt;        End If&lt;br /&gt;    End Sub&lt;br /&gt;End Module&lt;br /&gt;  &lt;br /&gt;The NodeType property of XmlTextReader is important when you want to know the content type of a document. The XmlNodeType enumeration has a member for each type of XML item such as Attribute, CDATA, Element, Comment, Document, DocumentType, Entity, ProcessInstruction, WhiteSpace and so on.&lt;br /&gt;&lt;br /&gt;List 2 code sample reads an XML document, finds a node type and writes information at the end with how many node types a document has.  &lt;br /&gt;&lt;br /&gt;List 2. Retrieving NodeType Information  &lt;br /&gt;&lt;br /&gt;' Import System.Xml namespace&lt;br /&gt;Imports System.Xml&lt;br /&gt; &lt;br /&gt;Module Module1&lt;br /&gt; &lt;br /&gt;    Sub Main()&lt;br /&gt; &lt;br /&gt;        Dim ws, pi, dc, cc, ac, et, el, xd As Integer&lt;br /&gt; &lt;br /&gt;        ' Read a document&lt;br /&gt;        Dim textReader As XmlTextReader = New&lt;br /&gt;XmlTextReader("C:\\books.xml")&lt;br /&gt; &lt;br /&gt;        ' Read until end of file&lt;br /&gt;        While textReader.Read()&lt;br /&gt; &lt;br /&gt;            Dim nType As XmlNodeType = textReader.NodeType&lt;br /&gt; &lt;br /&gt;            ' If node type us a declaration&lt;br /&gt;            If nType = XmlNodeType.XmlDeclaration Then&lt;br /&gt;                Console.WriteLine("Declaration:" +&lt;br /&gt;textReader.Name.ToString())&lt;br /&gt;                xd = xd + 1&lt;br /&gt;            End If&lt;br /&gt;            ' if node type is a comment&lt;br /&gt;            If nType = XmlNodeType.Comment Then&lt;br /&gt;                Console.WriteLine("Comment:" + textReader.Name.ToString())&lt;br /&gt;                cc = cc + 1&lt;br /&gt;            End If&lt;br /&gt;            ' if node type us an attribute&lt;br /&gt;            If nType = XmlNodeType.Attribute Then&lt;br /&gt;                Console.WriteLine("Attribute:" +&lt;br /&gt;textReader.Name.ToString())&lt;br /&gt;                ac = ac + 1&lt;br /&gt;            End If&lt;br /&gt;            ' if node type is an element&lt;br /&gt;            If nType = XmlNodeType.Element Then&lt;br /&gt;                Console.WriteLine("Element:" + textReader.Name.ToString())&lt;br /&gt;                el = el + 1&lt;br /&gt;            End If&lt;br /&gt;            ' if node type is an entity&lt;br /&gt;            If nType = XmlNodeType.Entity Then&lt;br /&gt;                Console.WriteLine("Entity:" + textReader.Name.ToString())&lt;br /&gt;                et = et + 1&lt;br /&gt;            End If&lt;br /&gt; &lt;br /&gt;            ' if node type is a Process Instruction&lt;br /&gt;            If nType = XmlNodeType.Entity Then&lt;br /&gt;                Console.WriteLine("Entity:" + textReader.Name.ToString())&lt;br /&gt;                pi = pi + 1&lt;br /&gt;            End If&lt;br /&gt; &lt;br /&gt;            ' if node type a document&lt;br /&gt;            If nType = XmlNodeType.DocumentType Then&lt;br /&gt;                Console.WriteLine("Document:" +&lt;br /&gt;textReader.Name.ToString())&lt;br /&gt;                dc = dc + 1&lt;br /&gt;            End If&lt;br /&gt;            ' if node type is white space&lt;br /&gt;            If nType = XmlNodeType.Whitespace Then&lt;br /&gt;                Console.WriteLine("WhiteSpace:" +textReader.Name.ToString())&lt;br /&gt;                ws = ws + 1&lt;br /&gt;            End If&lt;br /&gt;        End While&lt;br /&gt;Console.WriteLine("Total Comments:" + cc.ToString())&lt;br /&gt;        Console.WriteLine("Total Attributes:" + ac.ToString())&lt;br /&gt;        Console.WriteLine("Total Elements:" + el.ToString())&lt;br /&gt;        Console.WriteLine("Total Entity:" + et.ToString())&lt;br /&gt;        Console.WriteLine("Total Process Instructions:" + pi.ToString())&lt;br /&gt;        Console.WriteLine("Total Declaration:" + xd.ToString())&lt;br /&gt;        Console.WriteLine("Total DocumentType:" + dc.ToString())&lt;br /&gt;        Console.WriteLine("Total WhiteSpaces:" + ws.ToString())&lt;br /&gt; &lt;br /&gt;    End Sub&lt;br /&gt;End Module&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Writing XML Documents&lt;/strong&gt; &lt;br /&gt;The XmlWriter class contains the functionality to write to XML documents. It is an abstract base class used through XmlTextWriter and XmlNodeWriter classes. It contains methods and properties to write to XML documents. This class has many Writexxx method to write every type of item of an XML document. For example, WriteNode, WriteString, WriteAttributes, WriteStartElement, and WriteEndElement are some of them. Some of these methods are used in a start and end pair. For example, to write an element, you need to call WriteStartElement then write a string followed by WriteEndElement. &lt;br /&gt;&lt;br /&gt;Besides many methods, this class has three properties. WriteState, XmlLang, and XmlSpace. The WriteState gets and sets the state of the &lt;strong&gt;XmlWriter&lt;/strong&gt; class.  &lt;br /&gt;&lt;br /&gt;Although it’s not possible to describe all the Writexxx methods here, let’s see some of them here.&lt;br /&gt;&lt;br /&gt;First thing we need to do is create an instance of XmlTextWriter using its constructor. XmlTextWriter has three overloaded constructors, which can take a string, stream, or a TextWriter as an argument. We’ll pass a string (file name) as an argument, which we’re going to create. In my sample example, I create a file myXmlFile.xml in C:\\ dir.&lt;br /&gt;&lt;br /&gt;' Create a new file in C:\\ dir&lt;br /&gt;Dim textWriter As XmlTextWriter = New XmlTextWriter("C:\\myXmFile.xml",&lt;br /&gt;Nothing)&lt;br /&gt;&lt;br /&gt;After creating an instance, first thing you call us WriterStartDocument. When you’re done writing, you call WriteEndDocument and TextWriter’s Close method.&lt;br /&gt;  &lt;br /&gt; textWriter.WriteStartDocument()&lt;br /&gt;  &lt;br /&gt;………..  &lt;br /&gt;textWriter.WriteEndDocument() &lt;br /&gt;textWriter.Close()  &lt;br /&gt;&lt;br /&gt;The WriteStartDocument and WriteEndDocument methods open and close a document for writing. You must have to open a document before start writing to it.  WriteComment method writes comment to a document. It takes only one string type of argument. WriteString method writes a string to a document. With the help of WriteString, WriteStartElement and WriteEndElement methods pair can be used to write an element to a document. The WriteStartAttribute and WriteEndAttribute pair writes an attribute.&lt;br /&gt;&lt;br /&gt;WriteNode is more write method, which writes an XmlReader to a document as a node of the document. For example, you can use WriteProcessingInstruction and WriteDocType methods to write a ProcessingInstruction and DocType items of a document.&lt;br /&gt;&lt;br /&gt;'Write the ProcessingInstruction node&lt;br /&gt;Dim PI As String = "type='text/xsl' href='book.xsl'"&lt;br /&gt;textWriter.WriteProcessingInstruction("xml-stylesheet", PI)&lt;br /&gt; &lt;br /&gt;'Write the DocumentType node&lt;br /&gt;textWriter.WriteDocType("book", Nothing, Nothing, "&lt;!ENTITY h&lt;br /&gt;'softcover'&gt;")&lt;br /&gt;&lt;br /&gt;The below sample example summarizes all these methods and creates a new xml document with some items in it such as elements, attributes, strings, comments and so on. See Listing 5-14. In this sample example, we create a new xml file c:\xmlWriterText.xml. In this sample example, We create a new xml file c:\xmlWriterTest.xml using&lt;br /&gt;XmlTextWriter:  &lt;br /&gt;&lt;br /&gt;After that we add comments and elements to the document using Writexxx methods. After that we read our books.xml xml file using XmlTextReader and add its elements to xmlWriterTest.xml using XmlTextWriter.  &lt;br /&gt;&lt;br /&gt;List 3. Writing an XML document using XmlTextWriter&lt;br /&gt;&lt;br /&gt;' Import System.Xml namespace&lt;br /&gt;Imports System.Xml&lt;br /&gt; &lt;br /&gt;Module Module1&lt;br /&gt; &lt;br /&gt;    Sub Main()&lt;br /&gt; &lt;br /&gt;        ' Create a new file in C:\\ dir&lt;br /&gt;        Dim textWriter As XmlTextWriter = New&lt;br /&gt;XmlTextWriter("C:\\myXmFile.xml", Nothing)&lt;br /&gt; &lt;br /&gt;        ' Opens the document&lt;br /&gt;        textWriter.WriteStartDocument()&lt;br /&gt; &lt;br /&gt;        ' Write comments&lt;br /&gt;        textWriter.WriteComment("First Comment XmlTextWriter Sample&lt;br /&gt;Example")&lt;br /&gt;        textWriter.WriteComment("myXmlFile.xml in root dir")&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;        ' Write first element&lt;br /&gt;        textWriter.WriteStartElement("Student")&lt;br /&gt;        textWriter.WriteStartElement("r", "RECORD", "urn:record")&lt;br /&gt; &lt;br /&gt;        ' Write next element&lt;br /&gt;        textWriter.WriteStartElement("Name", "")&lt;br /&gt;        textWriter.WriteString("Student")&lt;br /&gt;        textWriter.WriteEndElement()&lt;br /&gt; &lt;br /&gt;        ' Write one more element&lt;br /&gt;        textWriter.WriteStartElement("Address", "")&lt;br /&gt;        textWriter.WriteString("Colony")&lt;br /&gt;        textWriter.WriteEndElement()&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;        ' WriteChars&lt;br /&gt;        textWriter.WriteStartElement("Char")&lt;br /&gt;        Dim ch() As Char = {"b", "l", "last"}&lt;br /&gt;        textWriter.WriteChars(ch, 0, ch.Length)&lt;br /&gt;        textWriter.WriteEndElement()&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;        ' Ends the document.&lt;br /&gt;        textWriter.WriteEndDocument()&lt;br /&gt;        ' close writer&lt;br /&gt;        textWriter.Close()&lt;br /&gt; &lt;br /&gt;    End Sub&lt;br /&gt;End Module &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using XmlDocument&lt;/strong&gt; &lt;br /&gt;The XmlDocument class represents an XML document. This class provides similar methods and properties we’ve discussed earlier in this article. &lt;br /&gt; &lt;br /&gt;Load and LoadXml are two useful methods of this class. A Load method loads XML data from a string, stream, TextReader or XmlReader. LoadXml method loads XML document from a specified string. Another useful method of this class is Save. Using Save method you can write XML data to a string, stream, TextWriter or XmlWriter. The following example in List 4 shows you how to use XmlDocument class’s Read, ReadXml and Save methods.  &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SGoRguGme6I/AAAAAAAAAJs/SNr96cqxB2A/s1600-h/Xml_code4.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SGoRguGme6I/AAAAAAAAAJs/SNr96cqxB2A/s320/Xml_code4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5218002372091345826" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;You can also use Save method to display contents on console if you pass Console.Out as a parameter. For example:  &lt;br /&gt;&lt;br /&gt;  doc.Save(Console.Out)  &lt;br /&gt;&lt;br /&gt;Here is one example of how to load an XML document using XmlTextReader. You read a file in an XmlTextReader and pass this in XmlDocument’s Load method to load the document.&lt;br /&gt;&lt;br /&gt;Dim doc As New XmlDocument()&lt;br /&gt;'Load the the document with the last book node.&lt;br /&gt;Dim reader As New XmlTextReader("c:\\books.xml")&lt;br /&gt;reader.Read()&lt;br /&gt;     &lt;br /&gt;doc.Load(reader)&lt;br /&gt;doc.Save(Console.Out)&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;XmlDataDocument and DataSet &lt;/strong&gt;&lt;br /&gt;The XmlDataDocument is used to provide synchronization between DataSet and XML documents. You can use XmlDataDocument to read an XML document and generate a DataSet or read data from a DataSet and generate an XML file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Viewing and Writing XML Data using ADO.NET DataSets&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Abstract&lt;/strong&gt;&lt;br /&gt;Based on a real world project this article shows how to handle XML data in .NET using VB.NET DataSets and DataViews. The article presents step-by-step how to bind, read and view XML data and generate graphical reports with the build-in Crystal Reports engine. The article puts special emphasize on XML standardization and interoperability issues experienced during the project, and presents workarounds for existing limitations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;This project was part of a larger project in the context of training acquisition and analysis. A Palm PDA is used for mobile data acquisition; these data are transferred onto a PC into a well-formed and valid XML data file. The task of this project was to develop a sophisticated data analysis and reporting application on the PC using the given XML data file.&lt;br /&gt;&lt;br /&gt;The .NET framework was chosen for the PC application because of its great data handling capabilities, its powerful graphic functionality and the built-in reporting engine Crystal Reports. We selected the programming language VB.NET because we believe, that this is the language of the future under .NET – and because there is no major difference between the supported languages in VS.NET with respect to their offered functionality.&lt;br /&gt;&lt;br /&gt;The idea was that both, the existing Palm application and the new VB.NET application can share one common XML file as its data source.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Access Methods in .NET&lt;/strong&gt;&lt;br /&gt;.NET offers numerous XML-related classes for reading and writing XML documents. Although the documentation states, that any class conforms to the W3C XML 1.0 standard, there are trade-offs in respect to performance, efficiency, productivity, and XML compliance between the different implementations.&lt;br /&gt;&lt;br /&gt;So we first investigated into these different access methods and then selected the most appropriate for our application. This step also addresses important issues that must be considered when dealing with legacy valid and well-formed XML data in .NET. &lt;br /&gt; &lt;br /&gt;The VB.NET developer can use any of the following five methods to access XML data:&lt;br /&gt;&lt;br /&gt;XmlTextReader &lt;br /&gt;XmlValidatingReader &lt;br /&gt;XmlDocument (and the rest of the DOM API), &lt;br /&gt;XPathNavigator. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ADO.NET DataSets&lt;/strong&gt;  &lt;br /&gt;The detailed description of these methods would go beyond the scope of this article. Thus the following table summarizes very briefly the characteristics of each method and shows when to use which technology. &lt;br /&gt; &lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoGfOtWZiI/AAAAAAAAAIs/a4vlqH5BZ_I/s1600-h/pic1_classes.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoGfOtWZiI/AAAAAAAAAIs/a4vlqH5BZ_I/s320/pic1_classes.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5217990251856160290" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Table 1. XML Data Access Methods in .NET&lt;br /&gt;&lt;br /&gt;When dealing with complex XML Schemas, then ADO.NET DataSet offers greatest support and flexibility. The DataSet, which can be used either relational databases or XML data files, is an in-memory cache of retrieved data. It is the major component for data handling in the ADO.NET architecture.&lt;br /&gt;&lt;br /&gt;The DataSet provides a consistent relational programming model regardless of the data source; thus it consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. A DataSet reads and writes data and schema as XML documents. The data and schema can be transported across HTTP and used by any application, on any platform that is XML-enabled.&lt;br /&gt;&lt;br /&gt;Considering all these features and the fact that this VB.NET application will need to be WebService interoperable with a server application in future we decided to go for DataSet’s. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;XML Conformance in .NET&lt;/strong&gt;&lt;br /&gt;Going with DataSets, ReadXML and ReadXMLSchema are the methods of choice to read the XML data, and the corresponding XML schema.&lt;br /&gt;&lt;br /&gt;However doing so with the given valid and well-formed XML data file, raised the following runtime error:  &lt;br /&gt;&lt;br /&gt;“The same table {description} cannot be the child table in two nested relations”  &lt;br /&gt;&lt;br /&gt;Looking deeper into the file shows that the valid and well-formed (and thus fully W3C compliant) XML file had a child table called “description” which had more than one parent table. This part of the XML Schema is shown in Figure 1 .  &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SGoHgnfKGPI/AAAAAAAAAJM/k5f1LjPJULM/s1600-h/xml_schema.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SGoHgnfKGPI/AAAAAAAAAJM/k5f1LjPJULM/s320/xml_schema.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5217991375199017202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 1. Original XML Schema &lt;br /&gt;&lt;br /&gt;This is a valid and allowed design according to the W3C XML schema specification. (Refer: W3C definition of Parent child Relationship). Also the XMLSpy tool validated this XML schema as valid and well-formed. &lt;br /&gt; &lt;br /&gt;More investigation showed that the .NET XML framework does not (yet?) support the full XML 1.0 standard. It does not support recursive schemas or designs where a child node type is beneath more than one parent node type. Of course, also all classes based on DataSets, like the System.Windows.Forms.DataGrid, which we were going to use, have the same restriction. In other words:  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Design Issue&lt;/strong&gt; 1:  “.NET Datasets require that a table can only be a child of one other table.” &lt;br /&gt; &lt;br /&gt;Microsoft has identified this as a bug (Q325695) and their knowledge base article [MS-Q325695] gives more information.&lt;br /&gt;There are essentially three ways to solve this problem:&lt;br /&gt;&lt;br /&gt;i)   Write custom functions &lt;br /&gt;ii)  Write a converter &lt;br /&gt;iii) Change your XML Schema  &lt;br /&gt;&lt;br /&gt;If you can’t break change the existing XML Schema (for example because you are not the owner of the file), there are two ways to solve the problem: you customize all your ode, or you write a converter.&lt;br /&gt;&lt;br /&gt;Customizing all your code means you write special methods for the XmlReader class and add records to a table with a hierarchical type design. You also have to implement a custom filtering mechanism if you want to display this data in bound controls, and a custom writing mechanism to write to the type of hierarchical format you are reading from. Even worse, any change in the schema file will cause changes in all of your&lt;br /&gt;&lt;br /&gt;custom functions – so this isn’t really an.&lt;br /&gt;&lt;br /&gt;The second option, if you can’t change the given XML Schema, is to write a converter. That means you define a new .NET compliant XML Schema for the given XML file and make use of the given DataSet capabilities. Then you write a bi-directional converter to convert the data from one XML Schema into the other before you use it. Although this still causes additional effort, it causes the least additional effort.&lt;br /&gt;If you are the owner of the XML Schema file, then solution is to change the given the given XML Schema and make it also .NET compliant. In our situation, this meant, to define three different description type structures (Idescription, Ddecscription, Fdescription), for the three occurrences of the description.&lt;br /&gt;&lt;br /&gt;To avoid multiple definitions of the same structure (which can cause maintenance errors in the future), we made use of the inheritance capabilities of XML Schema. We derived the three description types from the still existing base structure “description”. The details are shown in figure 2.  &lt;br /&gt;  &lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoGfOFPcPI/AAAAAAAAAI0/2Af_hLmOl6I/s1600-h/1child_several_par.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoGfOFPcPI/AAAAAAAAAI0/2Af_hLmOl6I/s320/1child_several_par.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5217990251687932146" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 2. Avoid one child with several parents &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Reading XML Data with DataSets&lt;/strong&gt;&lt;br /&gt;VB.NET developers have several approaches of using a DataSet in the applications. This section explains the chosen approach to create a DataSet from the modified XML Schema, the tools that were used and how we populated the DataSet from the XML source file.&lt;br /&gt;&lt;br /&gt;A DataSet can be typed or untyped. A typed DataSet is a dataset, which is created based a given XML Schema definition file (XSD file). Information from the schema (tables, columns, etc.) is generated and compiled into the new DataSet class as a set of first-class objects and properties.&lt;br /&gt;&lt;br /&gt;Because a typed DataSet class inherits from the base DataSet class, the typed class assumes all of the functionality of the DataSet class and can be used with methods that take an instance of a DataSet class as a parameter&lt;br /&gt;&lt;br /&gt;An untyped DataSet, in contrast, has no corresponding built-in schema. As in a typed dataset, an untyped DataSet contains tables, columns — but those are exposed only as collections. (However, after manually creating the tables and other data elements in an untyped DataSet, you can export the DataSet 's structure as a schema using the DataSet 's WriteXmlSchema method.) &lt;br /&gt;&lt;br /&gt;You can use either type of DataSet in your application. However, Visual Studio has more tool support for typed DataSets, and they make programming with the DataSet much easier and less error-prone. So having considered all these options the decision was to go with ADO.NET typed DataSets.&lt;br /&gt;&lt;br /&gt;Typed Datasets can be generated with the &lt;strong&gt;XSD.EXE&lt;/strong&gt; tool, which is part of the VS.NET environment. The tool accepts a valid XML Schema file as input, as well as the language to use (C#, VB).  The following line shows a typical command line of the tool which uses the XML Schema file XSDSchemaFileName.xsd. &lt;br /&gt; &lt;br /&gt;xsd.exe /d /l:VB.NET XSDSchemaFileName.xsd /n:XSDSchema.Namespace  &lt;br /&gt;&lt;br /&gt;The /d directive tells the tool to generate DataSets, /l specifies the language to use, the optional /n defines the namespace to generate. The generated DataSet classes will be saved in the source file XSDSchemaFileName.vb.&lt;br /&gt;Once the Typed DataSet classes are generated, the further procedure is almost a child’s play. The provided methods and properties guarantee data access in a type safe manner.&lt;br /&gt;&lt;br /&gt;So the next step was to populate the Typed DataSet at runtime from the XML file. The ReadXml() and the WriteXml() methods of the typed DataSet class do this very easily  without any difficulty as the following to lines of code show:  &lt;br /&gt;&lt;br /&gt;Dim myDS As New DataSet()&lt;br /&gt;myDS.ReadXml("input.xml", XmlReadMode.ReadSchema) &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Viewing XML Data&lt;/strong&gt;&lt;br /&gt;Having created and populated the DataSet the next step was to bind the data to the windows controls for user interaction. Since we were going to implement a grid view, this involved binding DataTables to DataGrids with user navigation facilities and providing parent-child relationships in the grid view so when a user selects a parent row, the corresponding child rows are to be shown automatically for editing purposes. &lt;br /&gt;&lt;br /&gt;The DataTable is the primary building block of ADO.NET. The DataTable is made up of a DataColumn and DataRow collections. The columns define the schema of the DataTable and the rows make up the actual data in the DataTable. A DataView is a bindable, customized view of a DataTable. You can create multiple DataView's of the same DataTable, each one can contain different data sorted in different order. &lt;br /&gt;&lt;br /&gt;Additionally, you can add, delete, or edit information in each DataView.&lt;br /&gt;DataTable and DataView use the same instances of DataColumns, i.e. they share the common structure. However DataTable and DataView each have its own row collections. The DataTable is consists of DataRow's while the DataView is made up DataRowView's. Figure 3 shows the relationship between DataSet, DataTable and DataView.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoGfXb2fCI/AAAAAAAAAI8/iCA5KJoyvek/s1600-h/Tables_views.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SGoGfXb2fCI/AAAAAAAAAI8/iCA5KJoyvek/s320/Tables_views.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5217990254198684706" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 3. Tables and Views  &lt;br /&gt;&lt;br /&gt;The data binding of typed DataSets is very smooth in VB.NET. You can bind the data sources to the WindowsForms controls at design time or runtime without any difficulty. For example, you can specify which data column to be bound to a ComboBox  in a WindowsForm  by setting  the DataSource and DataMember property of that control so that it gets automatically bound at runtime.&lt;br /&gt;&lt;br /&gt;We used the .NET DataView class to bind DataTables to the DataGrid. DataView supports data filtering and data sorting at design time or at runtime. For convenience a default DataView is generated for the developer for customization.&lt;br /&gt;In the analysis part, the application needs to display some statistical information, which is calculated from several columns and which is shown in some dynamically generated extra columns as shown in Figure 4 .&lt;br /&gt;  &lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoGfa_p3rI/AAAAAAAAAJE/zt6jnhf40_g/s1600-h/data_view.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoGfa_p3rI/AAAAAAAAAJE/zt6jnhf40_g/s320/data_view.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5217990255154159282" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 4. The data view&lt;br /&gt;&lt;br /&gt;Some of the data columns needed for these calculations were in different parent and child tables. Unfortunately it was not possible join two tables in the dataset  to show up in a single DataGrid.(for example, by using the DataSet.Relations property).To further clarify the situation  say I have two Parent &amp; child tables Table1(id,columnA,columnB) and Table2(id,columnC,columnD)  and I want resulting datagrid columns to be view like (columnA , columnB , columnC , columnD). It is similar to the situation if I had wrote a sql query like &lt;br /&gt;&lt;br /&gt;     select a.id , a.columnA , a.columnB , b.[columnC] , b.[columnD]  &lt;br /&gt;     From Table1 a , Table2 b &lt;br /&gt;     where a.id =b.id &lt;br /&gt;&lt;br /&gt;It is important   to understand that DataView is not equivalent of a SQL VIEW. A Dataset does not contain a query processor and has no mechanism to perform a join.&lt;br /&gt;  &lt;br /&gt;The other way to do it (most developers seems to suggest) is to simply create a new datatable &lt;br /&gt;&lt;br /&gt;That is typed the way you want it and manually moved the data from both  datatables to the new one. Also any data manipulation has to copy over to the original tables using a nested loops. This is a brute force method. It would be nice to here if anyone come up with something else. &lt;br /&gt;&lt;br /&gt;Finally more references were added to the  schema file. But that is not the best workaround. The reason that the columns could not be merged is founded in the relational programming model of the DataSets. The existing XML file uses nested child tables instead of references. This is not (yet?) resolved by the .NET DataSets, so that references are missing to cross-reference tables and to establish relationships. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;XML Design Issue 2:&lt;/strong&gt;  “Use references in XML data files instead of nested child tables to show up a joined table  in a single DataGrid”  &lt;br /&gt;So the next change was to introduce references where needed.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_xmdzLHNex7Q/SGoRgvVvdSI/AAAAAAAAAJ0/3E_-7-jdCX0/s1600-h/Adding_references_to_tables.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_xmdzLHNex7Q/SGoRgvVvdSI/AAAAAAAAAJ0/3E_-7-jdCX0/s320/Adding_references_to_tables.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5218002372423284002" /&gt;&lt;/a&gt;  &lt;br /&gt;&lt;br /&gt;Figure 5. Adding references to tables&lt;br /&gt;  &lt;br /&gt;In our application we use the Date column as a filter criteria for the generated graphs in the Crystal Report Engine. Thus in Figure 5 a Date column has been added to the session table, which is a direct reference of the date column of the day table.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reporting XML Data&lt;/strong&gt;&lt;br /&gt;Having completed the data binding to Windows forms the next task was to generate the summarized reports in both graphical and tabular forms. We have chosen the Crystal Reports Engine (which is delivered with the VS.NET environment) with its powerful dynamic reporting capabilities.&lt;br /&gt;&lt;br /&gt;Crystal Reports for Visual Studio .NET offers the following three object models:&lt;br /&gt;&lt;br /&gt;&gt;The Engine Object Model &lt;br /&gt;&gt;The Windows Forms Viewer Object Model &lt;br /&gt;&gt;The Web Forms Viewer Object Model  &lt;br /&gt;&lt;br /&gt;The top level Engine object model is the report document object. The report document object offers sophisticated control over your object. It contains all the properties and methods needed to interface with and customize a report. How ever it does not provide the display of the reports.&lt;br /&gt;&lt;br /&gt;This is where viewer objects and the report document objects come together. The Windows Forms viewer allows you to view a report in a Windows application and the Web Forms viewer does it for a Web application.&lt;br /&gt;&lt;br /&gt;So we selected the Engine Object model together with the Windows Object Model to accomplish the requirements. The Vb.NET CrystalDecisions.Windows.Forms namespace in the CrystalDecisions.Windows.Forms.dll assembly provides support for the Windows Forms Viewer control and its associated classes. It can also dynamically update the report being hosted and interact with controls within a windows application.&lt;br /&gt;&lt;br /&gt;When using the Crystal Report Engine you basically have two options for the selection of data source. The first one is passing the raw XML file, and the second is passing the populated DataSet to the Crystal Report Engine.&lt;br /&gt;When using the first approach you have to verify on every usage, that the XML file contains correct data types (data validation). Otherwise Crystal Report Engine would interpret the data types in the XML files differently (e.g. float are used as strings), which prevents the data from being processed further within Crystal Reports.&lt;br /&gt;&lt;br /&gt;The second, recommended option is passing the already populated typed DataSets to the Crystal Report Engine. This saves the runtime verification of data types. The content and the scope of the report is determined at runtime according to the user selection of the required report format. Crystal Reports provides template files for this. Figure 6 shows a sample report. &lt;br /&gt;&lt;br /&gt;Figure 6. Crystal Report View &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br /&gt;Visual Studio .NET has a very rich set of tightly integrated tools that work together to support C# application developer. For XML based applications it provides schema generation and validation tools. It offers the methods of choice for XML handling. Especially the DataSet classes make reading and writing of XML data extremely easy. The DataSet classes provide easy data binding to the GUI and to even third-party tools like Crystal Reports for advanced reporting.&lt;br /&gt;&lt;br /&gt;Other very nice new features are the new source code documentation support and application installer production. The code documentation tool generates a very nice HTML documentation (they improved the JavaDoc style), which is completely XML based. The integrated application installer allows easy creation of a setup program for your application.&lt;br /&gt;&lt;br /&gt;Despite the currently existing limitations of DataSets concerning its XML standard support, it is the tool of choice for XML data handling with .NET.&lt;br /&gt;Once your XML data sources confirm to the “.NET XML standard” the rest can be handled without much difficulty. It offers lot of built-in powerful classes and methods for reading, writing and displaying data. This allows the developer to concentrate on the more important application logic rather than having to worry about data handling issues or framework specifics. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generating XML from SQL Database&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description&lt;/strong&gt; &lt;br /&gt;This sample shows how you can obtain a Dataset from (in this case) a SQL Server database, and then write it out to an XML Document. As an "Extra Added Bonus(tm)", it can show you how to write the schema as well. The SQL Server database in question is the venerable and useful Northwind database.&lt;br /&gt;&lt;br /&gt;The significant parameters are all declared at the beginning as strings, so that you can easily debug and tweak for your own usage. In this section, we create a connection string, a query string (in standard SQL) and specify a target filename. &lt;br /&gt;&lt;br /&gt;Then, we call the function, &lt;br /&gt;&lt;br /&gt;Shared Sub writeSQLQueryToFileAsXML(connString As String, query As String, filename As String)&lt;br /&gt; &lt;br /&gt;This function first gets a connection, creates an adapter and specifies the connection and command to run through it, then obtains a dataset from that adapter. &lt;br /&gt;&lt;br /&gt;This function then shows how you can write that DataSet out to a stream (in this case, a FileStream) as an XML document through the DataSet member, public void WriteXml(Stream). And if you've got some extra time on your hands, you can even uncomment the code in the last section, to write the DataSet's SCHEMA to a file!&lt;br /&gt;&lt;br /&gt;An interesting corollary to this example would be to stream the DataSet's XML out to an HTTPResponse's HTTPWriter.outputStream, but that is both the subject of another sample, and also perhaps more easily done through native SQL Server capabilities.&lt;br /&gt;&lt;br /&gt;Note that the XML that is written is output as a fragment, that is, there is no element, &lt;?xml version="1.0"?&gt; at the beginning, nor is there a unifying, single root node. While you will have to add both of these, this is really a sensible choice. First of all, only you, and your particular application context, can say what is the right name for the root node - is it &lt;DelinquentCustomers&gt;, or &lt;GoldStarCustomers&gt;? Secondly, it may be a node or set of nodes buried down inside a much larger document, such as a &lt;Contacts&gt; node under one of several &lt;Salesman&gt; nodes. Get the picture?&lt;br /&gt;&lt;br /&gt;Compiling and Running the code:&lt;br /&gt;&lt;br /&gt;vbc XMLGenFromSQLDbPB.vb&lt;br /&gt;Or&lt;br /&gt;vbc /r:System.dll,System.Data.dll,System.Xml.dll  XMLGenFromSQLDbPB.vb&lt;br /&gt;This will return you with the location where it had saved the XML file.You can specify it in the String s.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Source Code:&lt;/strong&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Data&lt;br /&gt;Imports System.Xml&lt;br /&gt;Imports System.Data.SqlClient&lt;br /&gt;Imports System.IO&lt;br /&gt;&lt;br /&gt;Namespace WriteXML&lt;br /&gt;Public Class WriteXML&lt;br /&gt;&lt;br /&gt;Shared Sub Main()&lt;br /&gt;&lt;br /&gt;'*******************************************************************&lt;br /&gt;' NOTE : YOU WILL NEED TO HAVE SQL SERVER (or MSDE) AVAILABLE, AND&lt;br /&gt;' YOU WILL NEED THE NORTHWIND DATABASE INSTALLED IN THE SQL SERVER&lt;br /&gt;' INSTANCE IN ORDER FOR THIS TO WORK. &lt;br /&gt;'&lt;br /&gt;' MODIFY THE FOLLOWING CONNECTION STRING AND QUERY STRING TO RUN&lt;br /&gt;' THIS SAMPLE AGAINST A DIFFERENT DATABASE AND/OR QUERY.&lt;br /&gt;'*******************************************************************&lt;br /&gt;&lt;br /&gt;Dim outputFileName As String = "C:/myXmlData" ' ".xml" will be appended.&lt;br /&gt;Dim connString As String = "user id=sa;password=password;" + "Database=northwind;server=(local);"&lt;br /&gt;Dim sqlQueryString As String = "SELECT * FROM Suppliers"&lt;br /&gt;&lt;br /&gt;' Here's the meat of the demonstration.&lt;br /&gt;writeSQLQueryToFileAsXML(connString, sqlQueryString, outputFileName)&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Wrote query results to {0}", outputFileName)&lt;br /&gt;End Sub 'Main&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shared Sub writeSQLQueryToFileAsXML(connString As String, query As String, filename As String)&lt;br /&gt;&lt;br /&gt;Dim myConn As New SqlConnection(connString)&lt;br /&gt;&lt;br /&gt;Dim adapter As New SqlDataAdapter()&lt;br /&gt;&lt;br /&gt;adapter.SelectCommand = New SqlCommand(query, myConn)&lt;br /&gt;&lt;br /&gt;' Build the DataSet&lt;br /&gt;Dim myDs As New DataSet()&lt;br /&gt;&lt;br /&gt;adapter.Fill(myDs)&lt;br /&gt;&lt;br /&gt;Dim myFs As FileStream = Nothing&lt;br /&gt;&lt;br /&gt;' Get a FileStream object&lt;br /&gt;myFs = New FileStream(filename + ".xml", FileMode.OpenOrCreate, FileAccess.Write)&lt;br /&gt;' Apply the WriteXml method to write an XML document&lt;br /&gt;myDs.WriteXml(myFs)&lt;br /&gt;' It is always good housekeeping to close a file.&lt;br /&gt;myFs.Close()&lt;br /&gt;End Sub 'writeSQLQueryToFileAsXML &lt;br /&gt;End Class 'WriteXML '**************************************************&lt;br /&gt;End Namespace 'WriteXML ' Uncomment the following code if you also want to&lt;br /&gt;' dump the DataSet's schema to a file...&lt;br /&gt;'***************************************************&lt;br /&gt;'&lt;br /&gt;' Get a FileStream object&lt;br /&gt;'&lt;br /&gt;myFs = new FileStream(filename+"_Schema.xml",&lt;br /&gt;'&lt;br /&gt;FileMode.OpenOrCreate,&lt;br /&gt;'&lt;br /&gt;FileAccess.Write);&lt;br /&gt;'&lt;br /&gt;myDs.WriteXmlSchema(myFs);&lt;br /&gt;'&lt;br /&gt;' It is always good housekeeping to close a file.&lt;br /&gt;'&lt;br /&gt;myFs.Close();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inserting Data to an XML Document&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The XmlNode and the XmlDocument classes can be used to insert XML data to an existing document or to a new document. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Adding namspace Reference&lt;/strong&gt;&lt;br /&gt;Since Xml classes are defined in the System.XML namespace, so first thing you need to do is to Add the System.XML reference to the project.&lt;br /&gt;&lt;br /&gt;Imports  System.Xml&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Loading XML to Document&lt;/strong&gt;&lt;br /&gt;LoadXml method of XmlDocument can be used to load XML data to a document or to load an existing XML document..&lt;br /&gt;&lt;br /&gt;' Load XML data to a document&lt;br /&gt;Dim  doc as  new XmlDocument();&lt;br /&gt;doc.LoadXml("&lt;XMLFile&gt;" +&lt;br /&gt;" &lt;SomeData&gt;Old Data&lt;/SomeData&gt;" + &lt;br /&gt;"&lt;/XMLFile&gt;") &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inserting XML Data&lt;/strong&gt;&lt;br /&gt;The below code inserts XML data to the file and saves file as InsertedDoc.xml. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Souce Code:&lt;/strong&gt;   &lt;br /&gt;Try&lt;br /&gt;Dim currNode As XmlNode&lt;br /&gt;Dim doc As New XmlDocument()&lt;br /&gt;doc.LoadXml(("&lt;XMLFile&gt;" + " &lt;SomeData&gt;Old Data&lt;/SomeData&gt;" + "&lt;/XMLFile&gt;"))&lt;br /&gt;Dim docFrag As XmlDocumentFragment = doc.CreateDocumentFragment()&lt;br /&gt;docFrag.InnerXml = "&lt;Inserted&gt;" + " &lt;NewData&gt;Inserted Data&lt;/NewData&gt;" + "&lt;/Inserted&gt;"&lt;br /&gt;' insert the availability node into the documentcurrNode = doc.DocumentElement.FirstChild;&lt;br /&gt;currNode.InsertAfter(docFrag, currNode.LastChild)&lt;br /&gt;'save the output to a filedoc.Save("InsertedDoc.xml");&lt;br /&gt;Catch e As Exception&lt;br /&gt;Console.WriteLine("Exception: {0}", e.ToString())&lt;br /&gt;End Try &lt;br /&gt;&lt;br /&gt;The output of the code looks like this - &lt;br /&gt;&lt;br /&gt;- &lt;XMLFile&gt; &lt;br /&gt;- &lt;SomeData&gt; &lt;br /&gt;  Old Data &lt;br /&gt;- &lt;Inserted&gt; &lt;br /&gt;  &lt;NewData&gt;Inserted Data&lt;/NewData&gt; &lt;br /&gt;  &lt;/Inserted&gt; &lt;br /&gt;  &lt;/SomeData&gt; &lt;br /&gt;  &lt;/XMLFile&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading XML Files in VB.NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The XmlReader and XmlTextReader classes are defined in the System.XML namespace.&lt;br /&gt;&lt;br /&gt;The XmlTextReader class is derived from XmlReader class. The XmlTextReader class can be used to read the XML documents. The read function of this document reads the document until end of its nodes.&lt;br /&gt;&lt;br /&gt;In this article, I will show you how to use XmlTextReader class to read an XML document and write data to the console.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Adding namspace Reference&lt;/strong&gt;&lt;br /&gt;Since Xml classes are defined in the System.XML namespace, so first thing you need to do is to Add the System.XML reference to the project.&lt;br /&gt;&lt;br /&gt;Imports  System.Xml&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Open an XML Document &lt;/strong&gt;&lt;br /&gt;The constructor of the XmlTextReader class opens an XML file. In this sample, I used an XML file called xmltest.xml in C\temp directory. You can download the attached file.&lt;br /&gt;&lt;br /&gt;' Open an XML file&lt;br /&gt;Dim reader As New XmlTextReader("C:\temp\xmltest.xml")&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading  Data&lt;/strong&gt; &lt;br /&gt;The Read method of the XmlTextReader class reads the data. &lt;br /&gt;&lt;br /&gt;While reader.Read()&lt;br /&gt;Console.WriteLine(reader.Name)&lt;br /&gt;End While&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Xml&lt;br /&gt;&lt;br /&gt;Namespace ReadXML&lt;br /&gt;End Namespace 'ReadXML&lt;br /&gt;' &lt;summary&gt;&lt;br /&gt;' Summary description for Class1.&lt;br /&gt;' &lt;/summary&gt;public class Class1&lt;br /&gt;&lt;br /&gt;Class1() &lt;br /&gt;Dim Main As Integer&lt;br /&gt;String() &lt;br /&gt;If (True) Then&lt;br /&gt;Try&lt;br /&gt;' Open an XML file&lt;br /&gt;Dim reader As New XmlTextReader("C:\temp\xmltest.xml")&lt;br /&gt;While reader.Read()&lt;br /&gt;Console.WriteLine(reader.Name)&lt;br /&gt;End While&lt;br /&gt;&lt;br /&gt;Catch e As Exception&lt;br /&gt;Console.WriteLine("Exception: {0}", e.ToString())&lt;br /&gt;End Try&lt;br /&gt;Return 0&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Writing XML Files in VB.NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The XmlWriter and XmlTextWriter classes are defined in the System.XML namespace.&lt;br /&gt;&lt;br /&gt;The XmlTextWriter class is derived from XmlWriter class, which represents a writer that provides fast non-cached forward-only way of generating XML documents based on  the W3C Extensible Markup Language (XML) 1.0 specification.&lt;br /&gt;&lt;br /&gt;In this article, I will show you how to use XmlTextWriter class to create an XML document and write data to the document.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Adding namspace Reference&lt;/strong&gt;&lt;br /&gt;Since Xml classes are defined in the System.XML namespace, so first thing you need to do is to Add the System.XML reference to the project.&lt;br /&gt;&lt;br /&gt;Imports System.Xml&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating an XML Document&lt;/strong&gt;&lt;br /&gt;The constructor of the XmlTextWriter class creates an XML file if file doesn't exist. In this sample, I create a new XML file called xmltest.xml in C\temp directory.&lt;br /&gt;&lt;br /&gt;Dim writer As New XmlTextWriter("C:\temp\xmltest.xml", Nothing)&lt;br /&gt;&lt;br /&gt;NOTE: If you don't want to write data in an XML file and want to display XML contents on the Console, pass Console.Out as a parameter of the constructor.&lt;br /&gt;Dim writer As New XmlTextWriter(Console.Out)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Adding Data to the Document&lt;/strong&gt;&lt;br /&gt;The WriteStartDocument method starts a new document. The WriteStartElement and the WriteEndElement pair is used to add a new element to the document. The WriteString writes a string to the document. &lt;br /&gt;&lt;br /&gt;writer.WriteStartDocument()&lt;br /&gt;writer.WriteComment("Commentss: XmlWriter Test Program")&lt;br /&gt;writer.WriteProcessingInstruction("Instruction", "Person Record")&lt;br /&gt;writer.WriteStartElement("p", "person", "urn:person")&lt;br /&gt;writer.WriteStartElement("LastName", "")&lt;br /&gt;writer.WriteString("Chand")&lt;br /&gt;writer.WriteEndElement()&lt;br /&gt;writer.WriteElementInt16("age", "", 25)&lt;br /&gt;writer.WriteEndDocument()&lt;br /&gt; &lt;br /&gt;Imports System&lt;br /&gt;Imports System.Xml&lt;br /&gt;&lt;br /&gt;Namespace WriteToXML&lt;br /&gt;&lt;br /&gt;' &lt;summary&gt; &lt;br /&gt;' Summary description for Class1. &lt;br /&gt;' &lt;/summary&gt; &lt;br /&gt;Public Class Class1&lt;br /&gt;&lt;br /&gt;Public Sub New()&lt;br /&gt;End Sub 'New&lt;br /&gt;&lt;br /&gt;'Entry point which delegates to C-style main Private Function&lt;br /&gt;Public Overloads Shared Sub Main()&lt;br /&gt;System.Environment.ExitCode = Main(System.Environment.GetCommandLineArgs())&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Overloads Public Shared Function Main(args() As String) As Integer&lt;br /&gt;Try&lt;br /&gt;' Creates an XML file is not exist &lt;br /&gt;Dim writer As New XmlTextWriter("C:\temp\xmltest.xml", Nothing)&lt;br /&gt;&lt;br /&gt;' Starts a new document &lt;br /&gt;writer.WriteStartDocument()&lt;br /&gt;'Write comments &lt;br /&gt;writer.WriteComment("Commentss: XmlWriter Test Program")&lt;br /&gt;writer.WriteProcessingInstruction("Instruction", "Person Record")&lt;br /&gt;' Add elements to the file &lt;br /&gt;writer.WriteStartElement("p", "person", "urn:person")&lt;br /&gt;writer.WriteStartElement("LastName", "")&lt;br /&gt;writer.WriteString("Chand")&lt;br /&gt;writer.WriteEndElement()&lt;br /&gt;writer.WriteStartElement("FirstName", "")&lt;br /&gt;writer.WriteString("Mahesh")&lt;br /&gt;writer.WriteEndElement()&lt;br /&gt;writer.WriteElementInt16("age", "", 25)&lt;br /&gt;&lt;br /&gt;' Ends the document &lt;br /&gt;writer.WriteEndDocument()&lt;br /&gt;Catch e As Exception&lt;br /&gt;Console.WriteLine("Exception: {0}", e.ToString())&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;Return 0&lt;br /&gt;End Function 'Main&lt;br /&gt;End Class 'Class1&lt;br /&gt;End Namespace 'WriteToXML&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating XML Documents with the XmlTextWriter Class&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;As XML's popularity and use in Web-enabled applications continues to rise, it is becoming more and more important to have a good understanding of how to create, consume, and alter XML documents through .NET. In simplest terms, an XML file is really nothing more than a bulky text file, and prior to .NET, many ASP developers, when needing to generate an XML file on the fly, simply Response.Writed out the content of the XML document. &lt;br /&gt;&lt;br /&gt;While Response.Write-ing an XML file works, it is far from ideal for a number of reasons. First, since it composes an XML document with strings, one has to worry about escaping those characters that are illegal in XML. There are a number of illegal characters that cannot appear in the text portion of an XML document. These are &lt;, &gt;, &amp;, ", and '. When generating an XML document as a string, you have to manually search for these illegal characters and escape them. Second, with complex XML documents with many namespaces, attributes, and elements, the code necessary to Response.Write out the document can become cryptic. &lt;br /&gt;&lt;br /&gt;Fortunately, the .NET Framework provides a class designed specifically to create XML documents, the System.Xml.XmlTextWriter class. By using this class to create XML documents you don't need to worry about illegal XML characters in the text portion of the XML document, and the end code is much cleaner. In this article we'll look at using the XmlTextWriter class to create XML documents on the fly. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Basics of the XmlTextWriter Class&lt;/strong&gt;&lt;br /&gt;The XmlTextWriter class contains a number of methods that are useful for starting and completing an XML document and for adding elements and attributes to the XML document. The most important methods are: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;WriteStartDocument()&lt;/strong&gt; - you should call this method to start creating an XML document. This will create the first line in the XML document, specifying that the file is an XML document and its encoding. &lt;br /&gt;&lt;strong&gt;WriteStartElement(string)&lt;/strong&gt; - this method creates a new element in the XML document with the name specified by the string input parameter. (You can also specify a namespace as a second, optional string parameter.) &lt;br /&gt;WriteElementString(name, text_value) - If you want to create an XML element with nothing but text content (i.e., no nested elements), you can use this method. &lt;br /&gt;&lt;strong&gt;WriteAttributeString(name, value)&lt;/strong&gt; - this method writes an attribute name and value to the current element. &lt;br /&gt;&lt;strong&gt;WriteEndElement()&lt;/strong&gt; - this method closes off the element created in the WriteStartElement(string) method call. &lt;br /&gt;&lt;strong&gt;WriteEndDocument()&lt;/strong&gt; - this method completes the writing of the XML document. &lt;br /&gt;&lt;strong&gt;Close()&lt;/strong&gt; - this method closes the underlying stream, writing the contents of the XML document to the specified file location. &lt;br /&gt;&lt;br /&gt;To get started using the XmlTextWriter class you need to specify the file and encoding in the class's constructor. The encoding needs to be of the type System.Text.Encoding; some example encoding values are: System.Text.Encoding.ASCII, System.Text.Encoding.Unicode, and System.Text.Encoding.UTF8. Alternatively, you can specify in the constructor that the output of the XmlTextWriter class should be squirted out to a specified Stream. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a Simple XML Document with XmlTextWriter&lt;/strong&gt;&lt;br /&gt;To demonstrate using the XmlTextWriter class let's create a simple XML document, saving it to a specified file location. This XML document will contain information about the current user visiting the page, and will have this structure: &lt;br /&gt;&lt;br /&gt;&lt;userInfo&gt;&lt;br /&gt;  &lt;browserInfo&gt;    &lt;br /&gt;    &lt;urlReferrer&gt;URL referrer info&lt;/urlReferrer&gt;&lt;br /&gt;    &lt;userAgent&gt;User agent referrer info&lt;/userAgent&gt;&lt;br /&gt;    &lt;userLanguages&gt;languages info&lt;/userLanguages&gt;&lt;br /&gt;  &lt;/browserInfo&gt;&lt;br /&gt;  &lt;visitInfo timeVisited="date/time the page was visited"&gt;&lt;br /&gt;    &lt;ip&gt;visitor's IP address&lt;/ip&gt;&lt;br /&gt;    &lt;rawUrl&gt;raw URL requested&lt;/rawUrl&gt;&lt;br /&gt;  &lt;/visitInfo&gt;&lt;br /&gt;&lt;/userInfo&gt;&lt;br /&gt;&lt;br /&gt;(This XML file structure was chosen so that it would illustrate using all of the XmlTextWriter methods discussed in the previous section.) &lt;br /&gt;The code needed to create this XML document through an ASP.NET Web page is shown below: &lt;br /&gt;&lt;br /&gt;&lt;%@ Import Namespace="System.Xml" %&gt;&lt;br /&gt;&lt;%@ Import Namespace="System.Text" %&gt;&lt;br /&gt;(script language="C#" runat="server")&lt;br /&gt;void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;  // Create a new XmlTextWriter instance&lt;br /&gt;  XmlTextWriter writer = new &lt;br /&gt;       XmlTextWriter(Server.MapPath("userInfo.xml"), Encoding.UTF8);&lt;br /&gt;    &lt;br /&gt;  // start writing!&lt;br /&gt;  writer.WriteStartDocument();&lt;br /&gt;  writer.WriteStartElement("userInfo");&lt;br /&gt;   &lt;br /&gt;    // Creating the &lt;browserInfo&gt; element&lt;br /&gt;    writer.WriteStartElement("browserInfo");&lt;br /&gt;    &lt;br /&gt;    if (Request.UrlReferrer == null)&lt;br /&gt;     writer.WriteElementString("urlReferrer", "none");&lt;br /&gt;   else&lt;br /&gt;     writer.WriteElementString("urlReferrer", &lt;br /&gt;                      Request.UrlReferrer.PathAndQuery);&lt;br /&gt;    &lt;br /&gt;      writer.WriteElementString("userAgent", Request.UserAgent);&lt;br /&gt;      writer.WriteElementString("userLanguages", &lt;br /&gt;                       String.Join(", ", Request.UserLanguages));&lt;br /&gt;    writer.WriteEndElement();&lt;br /&gt;   &lt;br /&gt;    // Creating the &lt;visitInfo&gt; element&lt;br /&gt;    writer.WriteStartElement("visitInfo");&lt;br /&gt;      writer.WriteAttributeString("timeVisited", DateTime.Now.ToString());&lt;br /&gt;      writer.WriteElementString("ip", Request.UserHostAddress);&lt;br /&gt;      writer.WriteElementString("rawUrl", Request.RawUrl);&lt;br /&gt;    writer.WriteEndElement();   &lt;br /&gt;   &lt;br /&gt;  writer.WriteEndElement();&lt;br /&gt;  writer.WriteEndDocument();&lt;br /&gt;  writer.Close();    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First, notice that the System.Xml and System.Text namespaces have been imported. The Page_Load event handler begins by creating a new XmlTextWriter instance, indicating that its content should be saved to the file userInfo.xml and that its encoding should be UTF8 (a translation of 16-bit unicode encoding into 8-bits). Note that for each element with nested elements a WriteStartElement(elementName) method is called, along with a matching WriteEndElement() after the inner content has been renderred. Furthermore, the WriteElementString(elementName, textValue) is used for those elements with just text content. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Emitting XML Content to the Browser Window Directly&lt;/strong&gt;&lt;br /&gt;The previous example demonstrates how to use the XmlTextWriter class to create an XML document and persist it to a file. While this may be precisely what you are after, oftentimes when creating an XML document in an ASP.NET Web page we want to emit the XML content's to the client requesting the Web page. While this could be done in the previous example by opening the userInfo.xml file after creating it and then Response.Write()ing its contents out, this approach is a bit of a hack.&lt;br /&gt; &lt;br /&gt;A better approach is to have the results of the XmlTextWriter emitted directly to the output stream. This can be accomplished quite easily, by changing one line of code in the previous code sample. In the XmlTextWriter constructor, rather than specifying a file path, we can specify a Stream. Specifically, we want to specify Response.OutputStream. When doing this you will need to make another small change to the ASP.NET Web page. In the &lt;@ Page ... &gt; directive you need to indicate the page's MIME type as text/xml. If you don't do this, some browsers may think the data being sent is for a standard HTML Web page, and will attempt to format the XML document just as they would an HTML page (which will hide the XML elements and remove all whitespace). &lt;br /&gt;&lt;br /&gt;The following code shows an abbreviated version of the previous code sample, with the changes in bold. &lt;br /&gt;&lt;@ Page ContentType="text/xml" %&gt;&lt;br /&gt;&lt;%@ Import Namespace="System.Xml" %&gt;&lt;br /&gt;&lt;%@ Import Namespace="System.Text" %&gt;&lt;br /&gt;(script language="C#" runat="server")&lt;br /&gt;void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;  // Create a new XmlTextWriter instance&lt;br /&gt;  XmlTextWriter writer = new &lt;br /&gt;       XmlTextWriter(Response.OutputStream, Encoding.UTF8);&lt;br /&gt;    &lt;br /&gt;  // start writing!&lt;br /&gt;  ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Notice that by viewing the live demo you are shown an XML document (even though you are visiting an ASP.NET Web page). This is the same XML document that, in the previous code sample, was saved to userInfo.xml. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;In this article we examined how to create an XML document using the System.Xml.XmlTextWriter class of the .NET Framework. The XmlTextWriter class can persist its generated XML document to a file location or a specified stream, in a number of encodings. Using the XmlTextWriter class has many advantages over building up an XML document one string at a time. The main ones being more legible code and not needing to worry about escaping illegal XML characters.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-7733048437847996945?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/7733048437847996945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=7733048437847996945' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/7733048437847996945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/7733048437847996945'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/07/net-xml.html' title='.NET Xml'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_xmdzLHNex7Q/SGoRe6FDM7I/AAAAAAAAAJU/xq_pg9z4EyI/s72-c/Xml_code1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-6690025739425264825</id><published>2008-06-20T05:02:00.000-07:00</published><updated>2008-06-20T05:14:14.171-07:00</updated><title type='text'>.NET Assembly</title><content type='html'>&lt;strong&gt;Introduction to .NET Assemblies&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is an assembly?&lt;/strong&gt;&lt;br /&gt;.An Assembly is a logical unit of code &lt;br /&gt;&lt;br /&gt;.Assembly physically exist as DLLs or EXEs &lt;br /&gt;&lt;br /&gt;.One assembly can contain one or more files &lt;br /&gt;&lt;br /&gt;.The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs &lt;br /&gt;&lt;br /&gt;.When you compile your source code by default the exe/dll generated is actually an assembly &lt;br /&gt;&lt;br /&gt;.Unless your code is bundled as assembly it can not be used in any other application &lt;br /&gt;&lt;br /&gt;.When you talk about version of a component you are actually talking about version of the assembly to which the component belongs. &lt;br /&gt;&lt;br /&gt;.Every assembly file contains information about itself. This information is called as Assembly Manifest. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is assembly manifest?&lt;/strong&gt;&lt;br /&gt;.Assembly manifest is a data structure which stores information about an assembly &lt;br /&gt;&lt;br /&gt;.This information is stored within the assembly file(DLL/EXE) itself &lt;br /&gt;&lt;br /&gt;.The information includes version information, list of constituent files etc. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is private and shared assembly?&lt;/strong&gt;&lt;br /&gt;The assembly which is used only by a single application is called as private assembly. Suppose you created a DLL which encapsulates your business logic. This DLL will be used by your client application only and not by any other application. In order to run the application properly your DLL must reside in the same folder in which the client application is installed. Thus the assembly is private to your application.&lt;br /&gt;&lt;br /&gt;Suppose that you are creating a general purpose DLL which provides functionality which will be used by variety of applications. Now, instead of each client application having its own copy of DLL you can place the DLL in 'global assembly cache'. Such assemblies are called as shared assemblies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Global Assembly Cache?&lt;/strong&gt;&lt;br /&gt;Global assembly cache is nothing but a special disk folder where all the shared assemblies will be kept. It is located under &lt;drive&gt;:\WinNT\Assembly folder.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How assemblies avoid DLL Hell?&lt;/strong&gt;&lt;br /&gt;As stated earlier most of the assemblies are private. Hence each client application refers assemblies from its own installation folder. So, even though there are multiple versions of same assembly they will not conflict with each other. Consider following example : &lt;br /&gt;&lt;br /&gt;.You created assembly Assembly1 &lt;br /&gt;&lt;br /&gt;.You also created a client application which uses Assembly1 say Client1 &lt;br /&gt;&lt;br /&gt;.You installed the client in C:\MyApp1 and also placed Assembly1 in this folder&lt;br /&gt; &lt;br /&gt;.After some days you changed Assembly1 &lt;br /&gt;&lt;br /&gt;.You now created another application Client2 which uses this changed Assembly1&lt;br /&gt; &lt;br /&gt;.You installed Client2 in C:\MyApp2 and also placed changed Assembly1 in this folder &lt;br /&gt;&lt;br /&gt;.Since both the clients are referring to their own versions of Assembly1 everything goes on smoothly &lt;br /&gt;&lt;br /&gt;Now consider the case when you develop assembly that is shared one. In this case it is important to know how assemblies are versioned. All assemblies has a version number in the form:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;major.minor.build.revision&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you change the original assembly the changed version will be considered compatible with existing one if the major and minor versions of both the assemblies match.&lt;br /&gt;&lt;br /&gt;When the client application requests assembly the requested version number is matched against available versions and the version matching major and minor version numbers and having most latest build and revision number are supplied.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I create shared assemblies?&lt;/strong&gt;&lt;br /&gt;Following steps are involved in creating shared assemblies : &lt;br /&gt;&lt;br /&gt;.Create your DLL/EXE source code &lt;br /&gt;&lt;br /&gt;.Generate unique assembly name using SN utility &lt;br /&gt;&lt;br /&gt;.Sign your DLL/EXE with the private key by modifying AssemblyInfo file &lt;br /&gt;&lt;br /&gt;.Compile your DLL/EXE&lt;br /&gt; &lt;br /&gt;.Place the resultant DLL/EXE in global assembly cache using AL utility &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I create unique assembly name?&lt;/strong&gt;&lt;br /&gt;Microsoft now uses a public-private key pair to uniquely identify an assembly. These keys are generated using a utility called SN.exe (SN stands for shared name). The most common syntax of is :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;sn -k mykeyfile.key&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Where k represents that we want to generate a key and the file name followed is the file in which the keys will be stored.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I sign my DLL/EXE?&lt;/strong&gt;&lt;br /&gt;Before placing the assembly into shared cache you need to sign it using the keys we just generated. You mention the signing information in a special file called AssemblyInfo. Open the file from VS.NET solution explorer and change it to include following lines :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[assembly:AssemblyKeyFile("file_path")]&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now recompile the project and the assembly will be signed for you.&lt;br /&gt;&lt;br /&gt;Note : You can also supply the key file information during command line compilation via /a.keyfile switch. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I place the assembly in shared cache?&lt;/strong&gt;&lt;br /&gt;Microsoft has provided a utility called AL.exe to actually place your assembly in shared cache.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;AL /i:my_dll.dll&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now your dll will be placed at proper location by the utility.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Hands On...&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now, that we have understood the basics of assemblies let us apply our knowledge by developing a simple shared assembly.&lt;br /&gt;&lt;br /&gt;In this example we will create a VB.NET component called SampleGAC ( GAC stands for Global Assembly Cache). We will also create a key file named sample.key. We will sign our component with this key file and place it in Global Assembly Cache.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1 : Creating our sample component&lt;/strong&gt;&lt;br /&gt;Here is the code for the component. It just includes one method which returns a string.&lt;br /&gt;&lt;br /&gt;imports system &lt;br /&gt;&lt;br /&gt;namespace BAJComponents &lt;br /&gt; public class Sample&lt;br /&gt;  public function GetData() as string &lt;br /&gt;   return "hello world" &lt;br /&gt;  end function &lt;br /&gt; end class &lt;br /&gt;end namespace &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2 : Generate a key file&lt;/strong&gt;&lt;br /&gt;To generate the key file issue following command at command prompt.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;sn -k sample.key&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This will generate the key file in the same folder&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 3 : Sign your component with the key&lt;/strong&gt;&lt;br /&gt;Now, wee will sign the assembly with the key file we just created.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;vbc sampleGAC.vb /t:library /a.keyfile:sample.key&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 4 : Host the signed assembly in Global Assembly Cache&lt;/strong&gt;&lt;br /&gt;We will use AL utility to place the assembly in Global Assembly Cache.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;AL /i:sampleGAC.dll&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;After hosting the assembly just go to WINNT\Assembly folder and you will find your assembly listed there. Note how the assembly folder is treated differently that normal folders.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 5 : Test that our assembly works &lt;/strong&gt;&lt;br /&gt;Now, we will create a sample client application which uses our shared assembly. Just create a sample code as listed below :&lt;br /&gt;&lt;br /&gt;imports system &lt;br /&gt;imports BAJComponents &lt;br /&gt;public class SampleTest &lt;br /&gt; shared sub main() &lt;br /&gt;  dim x as new sample &lt;br /&gt;  dim s as string="x".getdata() &lt;br /&gt;  console.writeline(s) &lt;br /&gt; end sub &lt;br /&gt;end class &lt;br /&gt;&lt;br /&gt;Compile above code using :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;vbc sampletest.vb /t:exe /r:&lt;assembly_dll_path_here&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now, copy the resulting EXE in any other folder and run it. It will display "Hello World" indicating that it is using our shared assembly.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-6690025739425264825?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/6690025739425264825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=6690025739425264825' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/6690025739425264825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/6690025739425264825'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-assembly.html' title='.NET Assembly'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-6125644374467721972</id><published>2008-06-13T04:13:00.000-07:00</published><updated>2008-12-09T16:00:15.912-08:00</updated><title type='text'>.NET Ado.Net</title><content type='html'>&lt;strong&gt;ADO .NET &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Most applications need data access at one point of time making it a crucial component when working with applications. Data access is making the application interact with a database, where all the data is stored. Different applications have different requirements for database access. VB .NET uses ADO .NET (Active X Data Object) as it's data access and manipulation protocol which also enables us to work with data on the Internet. Let's take a look why ADO .NET came into picture replacing ADO. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Evolution of ADO.NET &lt;/strong&gt;&lt;br /&gt;The first data access model, DAO (data access model) was created for local databases with the built-in Jet engine which had performance and functionality issues. Next came RDO (Remote Data Object) and ADO (Active Data Object) which were designed for Client Server architectures but soon ADO took over RDO. ADO was a good architecture but as the language changes so is the technology. With ADO, all the data is contained in a recordset object which had problems when implemented on the network and penetrating firewalls. ADO was a connected data access, which means that when a connection to the database is established the connection remains open until the application is closed. Leaving the connection open for the lifetime of the application raises concerns about database security and network traffic. Also, as databases are becoming increasingly important and as they are serving more people, a connected data access model makes us think about its productivity. For example, an application with connected data access may do well when connected to two clients, the same may do poorly when connected to 10 and might be unusable when connected to 100 or more. Also, open database connections use system resources to a maximum extent making the system performance less effective. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why ADO.NET?&lt;/strong&gt; &lt;br /&gt;To cope up with some of the problems mentioned above, ADO .NET came into existence. ADO .NET addresses the above mentioned problems by maintaining a disconnected database access model which means, when an application interacts with the database, the connection is opened to serve the request of the application and is closed as soon as the request is completed. Likewise, if a database is Updated, the connection is opened long enough to complete the Update operation and is closed. By keeping connections open for only a minimum period of time, ADO .NET conserves system resources and provides maximum security for databases and also has less impact on system performance. Also, ADO .NET when interacting with  the database uses XML and converts all the data into XML format for database related operations making them more efficient. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The ADO.NET Data Architecture &lt;/strong&gt;&lt;br /&gt;Data Access in ADO.NET relies on two components: &lt;strong&gt;DataSet&lt;/strong&gt; and &lt;strong&gt;Data Provider&lt;/strong&gt;. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;DataSet&lt;/strong&gt; &lt;br /&gt;The dataset is a disconnected, in-memory representation of data. It can be considered as a local copy of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database. When the use of this DataSet is finished, changes can be made back to the central database for updating. The data in DataSet can be loaded from any valid data source like Microsoft SQL server database, an Oracle database or from a Microsoft Access database. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Data Provider&lt;/strong&gt; &lt;br /&gt;The Data Provider is responsible for providing and maintaining the connection to the database. A DataProvider is a set of related components that work together to provide data in an efficient and performance driven manner. The .NET Framework currently comes with two DataProviders: the SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later and the OleDb DataProvider which allows us to connect to other types of databases like Access and Oracle. Each DataProvider consists of the following component classes: &lt;br /&gt;&lt;br /&gt;The &lt;strong&gt;Connection&lt;/strong&gt; object which provides a connection to the database&lt;br /&gt;The &lt;strong&gt;Command&lt;/strong&gt; object which is used to execute a command&lt;br /&gt;The &lt;strong&gt;DataReader&lt;/strong&gt; object which provides a forward-only, read only, connected recordset&lt;br /&gt;The &lt;strong&gt;DataAdapter&lt;/strong&gt; object which populates a disconnected DataSet with data and performs update &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Data access with ADO.NET can be summarized as follows:&lt;/strong&gt; &lt;br /&gt;A connection object establishes the connection for the application with the database. The command object provides direct execution of the command to the database. If the command returns more than a single value, the command object returns a DataReader to provide the data. Alternatively, the DataAdapter can be used to fill the Dataset object. The database can be updated using the command object or the DataAdapter. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFJXK08s18I/AAAAAAAAAHM/_eFPX8lieZI/s1600-h/adoarc.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFJXK08s18I/AAAAAAAAAHM/_eFPX8lieZI/s320/adoarc.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5211323562344634306" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Component classes that make up the Data Providers&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Connection Object&lt;/strong&gt; &lt;br /&gt;The Connection object creates the connection to the database. Microsoft Visual Studio .NET provides two types of Connection classes: the SqlConnection object, which is designed specifically to connect to Microsoft SQL Server 7.0 or later, and the OleDbConnection object, which can provide connections to a wide range of database types like Microsoft Access and Oracle. The Connection object contains all of the information required to open a connection to the database. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Command Object&lt;/strong&gt; &lt;br /&gt;The Command object is represented by two corresponding classes: SqlCommand and OleDbCommand. Command objects are used to execute commands to a database across a data connection. The Command objects can be used to execute stored procedures on the database, SQL commands, or return complete tables directly. Command objects provide three methods that are used to execute commands on the database: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ExecuteNonQuery:&lt;/strong&gt; Executes commands that have no return values such as INSERT, UPDATE or DELETE &lt;br /&gt;&lt;strong&gt;ExecuteScalar:&lt;/strong&gt; Returns a single value from a database query &lt;br /&gt;&lt;strong&gt;ExecuteReader:&lt;/strong&gt; Returns a result set by way of a DataReader object &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The DataReader Object&lt;/strong&gt; &lt;br /&gt;The DataReader object provides a forward-only, read-only, connected stream recordset from a database. Unlike other components of the Data Provider, DataReader objects cannot be directly instantiated. Rather, the DataReader is returned as the result of the Command object's ExecuteReader method. The SqlCommand.ExecuteReader method returns a SqlDataReader object, and the OleDbCommand.ExecuteReader method returns an OleDbDataReader object. The DataReader can provide rows of data directly to application logic when you do not need to keep the data cached in memory. Because only one row is in memory at a time, the DataReader provides the lowest overhead in terms of system performance but requires the exclusive use of an open Connection object for the lifetime of the DataReader. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The DataAdapter Object &lt;/strong&gt;&lt;br /&gt;The DataAdapter is the class at the core of ADO .NET's disconnected data access. It is essentially the middleman facilitating all communication between the database and a DataSet. The DataAdapter is used either to fill a DataTable or DataSet with data from the database with it's Fill method. After the memory-resident data has been manipulated, the DataAdapter can commit the changes to the database by calling the Update method. The DataAdapter provides four properties that represent database commands: &lt;br /&gt;&lt;br /&gt;SelectCommand&lt;br /&gt;InsertCommand&lt;br /&gt;DeleteCommand&lt;br /&gt;UpdateCommand &lt;br /&gt;&lt;br /&gt;When the Update method is called, changes in the DataSet are copied back to the database and the appropriate InsertCommand, DeleteCommand, or UpdateCommand is executed. &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-6125644374467721972?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/6125644374467721972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=6125644374467721972' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/6125644374467721972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/6125644374467721972'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-adonet.html' title='.NET Ado.Net'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_xmdzLHNex7Q/SFJXK08s18I/AAAAAAAAAHM/_eFPX8lieZI/s72-c/adoarc.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-5390998498310853618</id><published>2008-06-13T03:13:00.000-07:00</published><updated>2008-12-09T16:00:16.009-08:00</updated><title type='text'>.NET Generics</title><content type='html'>&lt;strong&gt;Generics in .NET 2.0&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Generics in .NET 2.0 is an exciting feature. But what are generics? Are they for you? Should you use them in your applications? In this article, we'll answer these questions and take a closer look at generics usage, and their capabilities and limitations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;&lt;br /&gt;Many of the languages in .NET, like C#, C++, and VB.NET (with option strict on), are strongly typed languages. As a programmer using these languages, you expect the compiler to perform type-safety checks. For instance, if you try to treat or cast a reference of the type Book as a reference of the type Vehicle, the compiler will tell you that such a cast is invalid.&lt;br /&gt;&lt;br /&gt;However, when it comes to collections in .NET 1.0 and 1.1, there is no help with type safety. Consider an ArrayList, for example. It holds a collection of objects. This allows you to place an object of just about any type into an ArrayList. Let's take a look at the code in Example 1.&lt;br /&gt;&lt;br /&gt;Example 1. Lack of type safety in ArrayList &lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;&lt;br /&gt;namespace TestApp&lt;br /&gt;{&lt;br /&gt;        class Test&lt;br /&gt;        {&lt;br /&gt;                [STAThread]&lt;br /&gt;                static void Main(string[] args)&lt;br /&gt;                {&lt;br /&gt;                        ArrayList list = new ArrayList();&lt;br /&gt;&lt;br /&gt;                        list.Add(3);&lt;br /&gt;                        list.Add(4);&lt;br /&gt;                        //list.Add(5.0);&lt;br /&gt;&lt;br /&gt;                        int total = 0;&lt;br /&gt;                        foreach(int val in list)&lt;br /&gt;                        {&lt;br /&gt;                                total = total + val;&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                        Console.WriteLine(&lt;br /&gt;                                "Total is {0}", total);&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I am creating an instance of ArrayList and adding 3 and 4 to it. Then I loop though the ArrayList, fetching the int values from it and adding them. This program will produce the result "Total is 7." Now, if I uncomment the statement: &lt;br /&gt;&lt;br /&gt;list.Add(5.0);&lt;br /&gt;the program will produce a runtime exception:&lt;br /&gt;&lt;br /&gt;Unhandled Exception: System.InvalidCastException: Specified cast is not valid.&lt;br /&gt;at TestApp.Test.Main(String[] args) in c:\workarea\testapp\class1.cs:line 18&lt;br /&gt;&lt;br /&gt;What went wrong? Remember that ArrayList holds a collection of objects. When you add a 3 to the ArrayList, you are boxing the value 3. When you loop though the list, you are unboxing the elements as int. However, when you add the value 5.0, you are boxing a double. On line 18, that double value is being unboxed as an int, and that is the cause of failure. &lt;br /&gt;&lt;br /&gt;(The above example, if it was written using VB.NET would not fail, however. The reason is VB.NET, instead of unboxing, invokes a method that converts the values into Integers. The VB.NET code will also fail if the value in ArrayList is not convertible to Integer. See Gotcha #9, "Typeless ArrayList Isn't Type-Safe," in my book .NET Gotchas for further details.)&lt;br /&gt;&lt;br /&gt;As a programmer who is used to the type safety provided by the language, you would rather have the problems pop up during compile time instead of runtime. This is where generics come in.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What Are Generics?&lt;/strong&gt;&lt;br /&gt;Generics allow you to realize type safety at compile time. They allow you to create a data structure without committing to a specific data type. When the data structure is used, however, the compiler makes sure that the types used with it are consistent for type safety. Generics provide type safety, but without any loss of performance or code bloat. While they are similar to templates in C++ in this regard, they are very different in their implementation.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using Generics Collections&lt;/strong&gt;&lt;br /&gt;The System.Collections.Generics namespace contains the generics collections in .NET 2.0. Various collections/container classes have been "parameterized." To use them, simply specify the type for the parameterized type and off you go. See Example 2:&lt;br /&gt;&lt;br /&gt;Example 2. Type-safe generic List&lt;br /&gt;&lt;br /&gt;List&lt;int&gt; aList = new List&lt;int&gt;();&lt;br /&gt;aList.Add(3);&lt;br /&gt;aList.Add(4);&lt;br /&gt;// aList.Add(5.0);&lt;br /&gt;int total = 0;&lt;br /&gt;foreach(int val in aList)&lt;br /&gt;{&lt;br /&gt;        total = total + val;&lt;br /&gt;}&lt;br /&gt;Console.WriteLine("Total is {0}", total);&lt;br /&gt;&lt;br /&gt;In Example 2, I am creating an instance of the generic List with the type int, given within the angle brackets (&lt;&gt;), as the parameterized type. This code, when executed, will produce the result "Total is 7." Now, if I uncomment the statement doubleList.Add(5.0);, I will get a compilation error. The compiler determines that it can't send the value 5.0 to the method Add(), as it only accepts an int. Unlike the example in Example 1, this code has type safety built into it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CLR Support for Generics&lt;/strong&gt;&lt;br /&gt;Generics is not a mere language-level feature. The .NET CLR recognizes generics. In that regard, the use of generics is a first-class feature in .NET. For each type of parameter used for a generic, a class is not rolled out in the Microsoft Intermediate Language (MSIL). In other words, your assembly contains only one definition of your parameterized data structure or class, irrespective of how many different types are used for that parameterized type. For instance, if you define a generic type MyList&lt;T&gt;, only one definition of that type is present in MSIL. When the program executes, different classes are dynamically created, one for each type for the parameterized type. If you use MyList&lt;int&gt; and MyList&lt;double&gt;, then two classes are created on the fly when your program executes. Let's examine this further in Example 3.&lt;br /&gt;&lt;br /&gt;Example 3. Writing a generic class &lt;br /&gt;&lt;br /&gt;//MyList.cs&lt;br /&gt;#region Using directives&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;&lt;br /&gt;namespace CLRSupportExample&lt;br /&gt;{&lt;br /&gt;        public class MyList&lt;T&gt;&lt;br /&gt;        {&lt;br /&gt;                private static int objCount = 0;&lt;br /&gt;&lt;br /&gt;                public MyList()&lt;br /&gt;                {&lt;br /&gt;                        objCount++;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                public int Count&lt;br /&gt;                {&lt;br /&gt;                        get&lt;br /&gt;                        {&lt;br /&gt;                                return objCount;&lt;br /&gt;                        }&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Program.cs&lt;br /&gt;#region Using directives&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;&lt;br /&gt;namespace CLRSupportExample&lt;br /&gt;{&lt;br /&gt;        class SampleClass {}&lt;br /&gt;&lt;br /&gt;        class Program&lt;br /&gt;        {&lt;br /&gt;                static void Main(string[] args)&lt;br /&gt;                {&lt;br /&gt;                        MyList&lt;int&gt; myIntList = new MyList&lt;int&gt;();&lt;br /&gt;                        MyList&lt;int&gt; myIntList2 = new MyList&lt;int&gt;();&lt;br /&gt;&lt;br /&gt;                        MyList&lt;double&gt; myDoubleList &lt;br /&gt;                                        = new MyList&lt;double&gt;();&lt;br /&gt;&lt;br /&gt;                        MyList&lt;SampleClass&gt; mySampleList &lt;br /&gt;                                        = new MyList&lt;SampleClass&gt;();&lt;br /&gt;                                        &lt;br /&gt;                        Console.WriteLine(myIntList.Count);&lt;br /&gt;                        Console.WriteLine(myIntList2.Count);&lt;br /&gt;                        Console.WriteLine(myDoubleList.Count);&lt;br /&gt;                        Console.WriteLine(mySampleList.Count);&lt;br /&gt;                        Console.WriteLine(&lt;br /&gt;                                new MyList&lt;sampleclass&gt;().Count);&lt;br /&gt;&lt;br /&gt;                        Console.ReadLine();&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I have created a generic class named MyList. To parameterize it, I simply inserted an angle bracket. The T within &lt;&gt; represents the actual type that will be specified when the class is used. Within the MyList class, I have a static field, objCount. I am incrementing this within the constructor so I can find out how many objects of that type are created by the user of my class. The Count property returns the number of instances of the same type as the instance on which it is called.&lt;br /&gt;&lt;br /&gt;In the Main() method, I am creating two instances of MyList&lt;int&gt;, one instance of MyList&lt;double&gt;, and two instances of MyList&lt;SampleClass&gt;, where SampleClass is a class I have defined. The question is: what will be the value of Count? That is, what is the output from the above program? Go ahead and think on this and try to answer this question before you read further.&lt;br /&gt;&lt;br /&gt;Have you worked the above question? Did you get the following answer?&lt;br /&gt;&lt;br /&gt;2&lt;br /&gt;2&lt;br /&gt;1&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;The first two values of 2 are for MyList&lt;int&gt;. The first value of 1 is for MyList&lt;double&gt;. The second value of 1 is for MyList&lt;SampleClass&gt;; only one instance of this type had been created at that point in the control flow. The last value of 2 is also for MyList&lt;SampleClass&gt;, since another instance of this type has been created at this point in the code. The above example illustrates that MyList&lt;int&gt; is a different class from MyList&lt;double&gt;, which in turn is a different class from MyList&lt;SampleClass&gt;. So, in this example, we have four classes of MyList: MyList&lt;T&gt;, MyList&lt;int&gt;, MyList&lt;double&gt;, and MyList&lt;X&gt;. Again, while there are four classes of MyList, only one is stored in MSIL. How can we prove this? Figure 1 shows the MSIL using the ildasm.exe tool.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFZBXUJbnRI/AAAAAAAAAHU/FB-wX58CCj0/s1600-h/fig1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFZBXUJbnRI/AAAAAAAAAHU/FB-wX58CCj0/s320/fig1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5212425487528992018" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 1. A look at MSIL for Example 3 &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generics Methods&lt;/strong&gt;&lt;br /&gt;In addition to having generic classes, you may also have generic methods. Generic methods may be part of any class. Let's look at Example 4:&lt;br /&gt;&lt;br /&gt;Example 4. A generic method&lt;br /&gt;&lt;br /&gt;public class Program&lt;br /&gt;{&lt;br /&gt;        public static void Copy&lt;T&gt;(List&lt;T&gt; source, List&lt;T&gt; destination)&lt;br /&gt;        {&lt;br /&gt;                foreach (T obj in source)&lt;br /&gt;                {&lt;br /&gt;                        destination.Add(obj);&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;                List&lt;int&gt; lst1 = new List&lt;int&gt;();&lt;br /&gt;                lst1.Add(2);&lt;br /&gt;                lst1.Add(4);&lt;br /&gt;&lt;br /&gt;                List&lt;int&gt; lst2 = new List&lt;int&gt;();&lt;br /&gt;                Copy(lst1, lst2);&lt;br /&gt;                Console.WriteLine(lst2.Count);&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The Copy() method is a generic method that works with the parameterized type T. When Copy() is invoked in Main(), the compiler figures out the specific type to use, based on the arguments presented to the Copy() method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Unbounded Type Parameters&lt;/strong&gt;&lt;br /&gt;If you create generics data structures or classes, like MyList in Example 3, there are no restrictions on what type the parametric type you may use for the parameteric type. This leads to some limitations, however. For example, you are not allowed to use ==, !=, or &lt; on instances of the parametric type: &lt;br /&gt;&lt;br /&gt;if (obj1 == obj2) …&lt;br /&gt;&lt;br /&gt;The implementation of operators such as == and != are different for value types and reference types. The behavior of the code may not be easier to understand if these were allowed arbitrarily. Another restriction is the use of default constructor. For instance, if you write new T(), you will get a compilation error, because not all classes have a no-parameter constructor. What if you do want to create an object using new T(), or you want to use operators such as == and !=? You can, but first you have to constraint the type that can be used for the parameterized type. Let's look at how to do that.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Constraints and Their Benefits&lt;/strong&gt;&lt;br /&gt;A generic class allows you to write your class without committing to any type, yet allows the user of your class, later on, to indicate the specific type to be used. While this gives greater flexibility by placing some constraints on the types that may be used for the parameterized type, you gain some control in writing your class. Let's look at an example:&lt;br /&gt;&lt;br /&gt;Example 5. The need for constraints: code that will not compile&lt;br /&gt;&lt;br /&gt;public static T Max&lt;T&gt;(T op1, T op2) &lt;br /&gt;{&lt;br /&gt;        if (op1.CompareTo(op2) &lt; 0)&lt;br /&gt;                return op1;&lt;br /&gt;        return op2;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The code in Example 5 will produce a compilation error:&lt;br /&gt;&lt;br /&gt;Error 1 'T' does not contain a definition for 'CompareTo'&lt;br /&gt;Assume I need the type to support the CompareTo() method. I can specify this by using the constraint that the type specified for the parameterized type must implement the IComparable interface. Example 6 has the code:&lt;br /&gt;Example 6. Specifying a constraint&lt;br /&gt;&lt;br /&gt;public static T Max&lt;T&gt;(T op1, T op2) where T : IComparable&lt;br /&gt;{&lt;br /&gt;        if (op1.CompareTo(op2) &lt; 0)&lt;br /&gt;                return op1;&lt;br /&gt;        return op2;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In Example 6, I have specified the constraint that the type used for parameterized type must inherit from (implement) IComparable. The following constraints may be used:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;where T : struct&lt;/strong&gt;          type must be a value type (a struct)&lt;br /&gt;&lt;strong&gt;where T : class&lt;/strong&gt;           type must be reference type (a class)&lt;br /&gt;&lt;strong&gt;where T : new()&lt;/strong&gt;           type must have a no-parameter constructor&lt;br /&gt;&lt;strong&gt;where T : class_name&lt;/strong&gt;      type may be either class_name or one of its sub-classes (or is below class_name in the inheritance hierarchy)&lt;br /&gt;&lt;strong&gt;where T :&lt;/strong&gt; interface_name  type must implement the specified interface&lt;br /&gt;&lt;br /&gt;You may specify a combination of constraints, as in: where T : IComparable, new(). This says that the type for the parameterized type must implement the IComparable interface and must have a no-parameter constructor.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Inheritance and Generics&lt;/strong&gt;&lt;br /&gt;A generic class that uses parameterized types, like MyClass1&lt;T&gt;, is called an open-constructed generic. A generic class that uses no parameterized types, like MyClass1&lt;int&gt;, is called a closed-constructed generic.&lt;br /&gt;&lt;br /&gt;You may derive from a closed-constructed generic; that is, you may inherit a class named MyClass2 from another class named MyClass1, as in:&lt;br /&gt;&lt;br /&gt;public class MyClass2&lt;T&gt; : MyClass1&lt;int&gt;&lt;br /&gt;You may derive from an open-constructed generic, provided the type is parameterized.&lt;br /&gt;&lt;br /&gt;For example: &lt;br /&gt;&lt;br /&gt;public class MyClass2&lt;T&gt; : MyClass2&lt;T&gt;&lt;br /&gt;is valid, but&lt;br /&gt;&lt;br /&gt;public class MyClass2&lt;T&gt; : MyClass2&lt;Y&gt;&lt;br /&gt;is not valid, where Y is a parameterized type. Non-generic classes may derive from closed-constructed generic classes, but not from open-constructed generic classes. That is, &lt;br /&gt;&lt;br /&gt;public class MyClass : MyClass1&lt;int&gt;&lt;br /&gt;is valid, but&lt;br /&gt;&lt;br /&gt;public class MyClass : MyClass1&lt;T&gt;&lt;br /&gt;is not.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generics and Substitutability&lt;/strong&gt;&lt;br /&gt;When we deal with inheritance, we need to be careful about substitutability. If B inherits from A, then anywhere an object of A is used, an object of B may also be used. Let's assume we have a Basket of Fruits (Basket&lt;Fruit&gt;). We have Apple and Banana (kinds of Fruits) inherit from Fruit. Should Basket of Apples (Basket&lt;apple&gt;) inherit from Basket of Fruits (Basket&lt;Fruit&gt;)? The answer is no, if we think about substitutability. Why? Consider a method that works with a Basket of Fruits:&lt;br /&gt;&lt;br /&gt;public void Package(Basket&lt;Fruit&gt; aBasket)&lt;br /&gt;{&lt;br /&gt;        aBasket.Add(new Apple());&lt;br /&gt;        aBasket.Add(new Banana());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If an instance of Basket&lt;Fruit&gt; is sent to this method, the method would add an Apple and a Banana. However, what would the effect be of sending an instance of a Basket&lt;Apple&gt; to this method? You see, this gets tricky. That is why if you write:&lt;br /&gt;&lt;br /&gt;Basket&lt;Apple&gt; anAppleBasket = new Basket&lt;Apple&gt;();&lt;br /&gt;Package(anAppleBasket);&lt;br /&gt;You will get an error:&lt;br /&gt;&lt;br /&gt;Error 2 Argument '1': &lt;br /&gt;cannot convert from 'TestApp.Basket&lt;testapp.apple&gt;' &lt;br /&gt;to 'TestApp.Basket&lt;testapp.fruit&gt;'&lt;br /&gt;&lt;br /&gt;The compiler protects us from shooting ourselves in the foot by making sure we don't arbitrarily pass a collection of derived where a collection of base is expected. That is pretty good, isn't it?&lt;br /&gt;&lt;br /&gt;Wait a minute, though! That was great in the above example, but there are times when I do want to pass a collection of derived where a collection of base is needed. For instance, consider an Animal (such as Monkey), which has a method named Eat that takes a Basket&lt;Fruit&gt;, as shown below:&lt;br /&gt;&lt;br /&gt;public void Eat(Basket&lt;Fruit&gt; fruits)&lt;br /&gt;{&lt;br /&gt;        foreach (Fruit aFruit in fruits)&lt;br /&gt;        {&lt;br /&gt;                // code to eat fruit&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now, you may call:&lt;br /&gt;&lt;br /&gt;Basket&lt;Fruit&gt; fruitsBasket = new Basket&lt;Fruit&gt;();&lt;br /&gt;… // Fruits added to Basket&lt;br /&gt;anAnimal.Eat(fruitsBasket);&lt;br /&gt;&lt;br /&gt;What if you have a Basket&lt;Banana&gt; with you? Would it make sense to send a Basket&lt;Banana&gt; to the Eat method? In this case, it would, no? But the compiler will give us an error if we try:&lt;br /&gt;&lt;br /&gt;Basket&lt;Banana&gt; bananaBasket = new Basket&lt;Banana&gt;();&lt;br /&gt;//…&lt;br /&gt;anAnimal.Eat(bananaBasket);&lt;br /&gt;&lt;br /&gt;The compiler is protecting us here. How can we ask the compiler to let us through in this particular case? Again, constraints come in handy for this:&lt;br /&gt;&lt;br /&gt;public void Eat&lt;t&gt;(Basket&lt;t&gt; fruits) where T : Fruit&lt;br /&gt;{&lt;br /&gt;foreach (Fruit aFruit in fruits)&lt;br /&gt;      {&lt;br /&gt;        // code to eat fruit&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In writing the Eat() method, I am asking the compiler to allow a Basket of any type T, where T is of the type Fruit or any class that inherits from Fruit.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generics and Delegates&lt;/strong&gt;&lt;br /&gt;Delegates can be generics as well. This provides quite a bit of flexibility. &lt;br /&gt;&lt;br /&gt;Assume we are interested in writing a framework. We need to provide a mechanism for an event source to talk to an object that is interested in the event. Our framework may not be able to control what the events are. You may be dealing with a stock price change (double price). I may be dealing with temperature change in a boiler (temperature value), where Temperature may be an object that has some information such as value, units, threshold, and so on. How can I define an interface for these events?&lt;br /&gt;&lt;br /&gt;Let's take a look at how we can realize this by using pre-generic delegates:&lt;br /&gt;&lt;br /&gt;    public delegate void NotifyDelegate(Object info);&lt;br /&gt;&lt;br /&gt;    public interface ISource&lt;br /&gt;    {&lt;br /&gt;        event NotifyDelegate NotifyActivity;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;We have the NotifyDelegate accepting an Object. This is the best we could do in the past, as Object can be use to represent different types such as double, Temperature, and so on, though it involves boxing overhead for value types. ISource is an interface that different sources will support. The framework exposes the NotifyDelegate delegate and the ISource interface.&lt;br /&gt;&lt;br /&gt;Let's look at two different sources:&lt;br /&gt;&lt;br /&gt;    public class StockPriceSource : ISource&lt;br /&gt;    {&lt;br /&gt;        public event NotifyDelegate NotifyActivity;&lt;br /&gt;        //…&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public class BoilerSource : ISource&lt;br /&gt;    {&lt;br /&gt;        public event NotifyDelegate NotifyActivity;&lt;br /&gt;        //…&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;If we have an object of each of the above classes, we would register a handler for events, as shown below:&lt;br /&gt;&lt;br /&gt;            StockPriceSource stockSource = new StockPriceSource();&lt;br /&gt;            stockSource.NotifyActivity &lt;br /&gt;                        += new NotifyDelegate(&lt;br /&gt;                                stockSource_NotifyActivity);&lt;br /&gt;&lt;br /&gt;            // Not necessarily in the same program… we may have&lt;br /&gt;            BoilerSource boilerSource = new BoilerSource();&lt;br /&gt;            boilerSource.NotifyActivity &lt;br /&gt;                        += new NotifyDelegate(&lt;br /&gt;                                boilerSource_NotifyActivity);&lt;br /&gt;&lt;br /&gt;In the delegate handler methods, we would do something like the following:&lt;br /&gt;For the handler for stock event, we would have:&lt;br /&gt;&lt;br /&gt;void stockSource_NotifyActivity(object info)&lt;br /&gt;{&lt;br /&gt;        double price = (double)info; &lt;br /&gt;        // downcast required before use&lt;br /&gt;}&lt;br /&gt;The handler for the temperature event may look like this:&lt;br /&gt;&lt;br /&gt;void boilerSource_NotifyActivity(object info)&lt;br /&gt;{&lt;br /&gt;        Temperature value = info as Temperature; &lt;br /&gt;        // downcast required before use&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The above code is not intuitive, and is messy with the downcasts. With generics, the code is more readable and easier to work with. Let's take a look at the code with generics at work:&lt;br /&gt;&lt;br /&gt;Here is the delegate and the interface:&lt;br /&gt;&lt;br /&gt;    public delegate void NotifyDelegate&lt;t&gt;(T info);&lt;br /&gt;&lt;br /&gt;    public interface ISource&lt;t&gt;&lt;br /&gt;    {&lt;br /&gt;        event NotifyDelegate&lt;t&gt; NotifyActivity;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;We have parameterized the delegate and the interface. The implementor of the interface can now say what the type should be.&lt;br /&gt;&lt;br /&gt;The Stock source would look like this: &lt;br /&gt;&lt;br /&gt;    public class StockPriceSource : ISource&lt;double&gt;&lt;br /&gt;    {&lt;br /&gt;        public event NotifyDelegate&lt;double&gt; NotifyActivity;&lt;br /&gt;        //…&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;and the Boiler source would look like this:&lt;br /&gt;&lt;br /&gt;    public class BoilerSource : ISource&lt;temperature&gt;&lt;br /&gt;    {&lt;br /&gt;        public event NotifyDelegate&lt;temperature&gt; NotifyActivity;&lt;br /&gt;        //…&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;If we have an object of each of the above classes, we would register a handler for events, as shown below:&lt;br /&gt;&lt;br /&gt;            StockPriceSource stockSource = new StockPriceSource();&lt;br /&gt;            stockSource.NotifyActivity &lt;br /&gt;                += new NotifyDelegate&lt;double&gt;(&lt;br /&gt;                        stockSource_NotifyActivity);&lt;br /&gt;&lt;br /&gt;            // Not necessarily in the same program… we may have&lt;br /&gt;            BoilerSource boilerSource = new BoilerSource();&lt;br /&gt;            boilerSource.NotifyActivity &lt;br /&gt;                += new NotifyDelegate&lt;temperature&gt;(&lt;br /&gt;                        boilerSource_NotifyActivity);&lt;br /&gt;Now, the event handler for stock price would be:&lt;br /&gt;&lt;br /&gt;        void stockSource_NotifyActivity(double info)&lt;br /&gt;        {&lt;br /&gt;                //…&lt;br /&gt;        }&lt;br /&gt;and the event handler for the temperature is:&lt;br /&gt;&lt;br /&gt;        void boilerSource_NotifyActivity(Temperature info)&lt;br /&gt;        {&lt;br /&gt;                //…&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;This code has no downcast and the types involved are very clear.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generics and Reflection&lt;/strong&gt;&lt;br /&gt;Since generics are supported at the CLR level, you may use reflection API to get information about generics. One thing may be a bit confusing when you are new to generics: you have to keep in mind that there is the generics class you write and then there are types created from it at runtime. So, when using the reflection API, you have to make an extra effort to keep in mind which type you are dealing with. I illustrate this in the Example 7:&lt;br /&gt;&lt;br /&gt;Example 7. Reflection on generics&lt;br /&gt;&lt;br /&gt;    public class MyClass&lt;t&gt; { }&lt;br /&gt;&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            MyClass&lt;int&gt; obj1 = new MyClass&lt;int&gt;();&lt;br /&gt;            MyClass&lt;double&gt; obj2 = new MyClass&lt;double&gt;();&lt;br /&gt;&lt;br /&gt;            Type type1 = obj1.GetType();&lt;br /&gt;            Type type2 = obj2.GetType();&lt;br /&gt;&lt;br /&gt;            Console.WriteLine("obj1's Type");&lt;br /&gt;            Console.WriteLine(type1.FullName);&lt;br /&gt;            Console.WriteLine(&lt;br /&gt;                type1.GetGenericTypeDefinition().FullName);&lt;br /&gt;&lt;br /&gt;            Console.WriteLine("obj2's Type");&lt;br /&gt;            Console.WriteLine(type2.FullName);&lt;br /&gt;            Console.WriteLine(&lt;br /&gt;                type2.GetGenericTypeDefinition().FullName);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;I have an instance of MyClass&lt;int&gt;. I ask for the class name of this instance. Then I ask for the GenericTypeDefinition() of this type. GenericTypeDefinition() will return the type metadata for MyClass&lt;T&gt; in this example. You may call IsGenericTypeDefinition to ask if this is a generic type (like MyClass&lt;T&gt;) or if its type parameters have been specified (like MyClass&lt;int&gt;). Similarly, I query an instance of MyClass&lt;double&gt; for its metadata. The output from the above program is shown below:&lt;br /&gt;&lt;br /&gt;obj1's Type&lt;br /&gt;TestApp.MyClass`1&lt;br /&gt;    [[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, &lt;br /&gt;    PublicKeyToken=b77a5c561934e089]]&lt;br /&gt;TestApp.MyClass`1&lt;br /&gt;obj2's Type&lt;br /&gt;TestApp.MyClass`1&lt;br /&gt;    [[System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, &lt;br /&gt;    PublicKeyToken=b77a5c561934e089]]&lt;br /&gt;TestApp.MyClass`1&lt;br /&gt;We can see that MyClass&lt;int&gt; and MyClass&lt;double&gt; are classes that belong to the mscorlib assembly (dynamically created), while the class MyClass&lt;t&gt; belongs to my assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Generics' Limitations&lt;/strong&gt;&lt;br /&gt;We have seen the power of generics so far in this article. Are there any limitations? There is one significant limitation, which I hope Microsoft addresses. In expressing constraints, we can specify that the parameter type must inherit from a class. How about specifying that the parameter must be a base class of some class? Why do we need that?&lt;br /&gt;&lt;br /&gt;In Example 4, I showed you a Copy() method that copied contents of a source List to a destination list. I can use it as follows:&lt;br /&gt;&lt;br /&gt;List&lt;Apple&gt; appleList1 = new List&lt;Apple&gt;();&lt;br /&gt;List&lt;Apple&gt; appleList2 = new List&lt;Apple&gt;();&lt;br /&gt;…&lt;br /&gt;Copy(appleList1, appleList2);&lt;br /&gt;However, what if I want to copy apples from one list into a list of Fruits (where Apple inherits from Fruit). Most certainly, a list of Fruits can hold Apples. So I want to write:&lt;br /&gt;&lt;br /&gt;List&lt;Apple&gt; appleList1 = new List&lt;Apple&gt;();&lt;br /&gt;List&lt;Fruit&gt; fruitsList2 = new List&lt;Fruit&gt;();&lt;br /&gt;…&lt;br /&gt;Copy(appleList1, fruitsList2);&lt;br /&gt;This will not compile. You will get an error:&lt;br /&gt;&lt;br /&gt;Error 1 The type arguments for method &lt;br /&gt;'TestApp.Program.Copy&lt;t&gt;(System.Collections.Generic.List&lt;t&gt;, &lt;br /&gt;System.Collections.Generic.List&lt;t&gt;)' cannot be inferred from the usage. &lt;br /&gt;&lt;br /&gt;The compiler, based on the call arguments, is not able to decide what T should be. What I really want to say is that the Copy should accept a List of some type as the first parameter, and a List of the same type or a List of its base type as the second parameter.&lt;br /&gt;&lt;br /&gt;Even though there is no way to say that a type must be a base type of another, you can get around this limitation by still using the constraints. Here is how:&lt;br /&gt;&lt;br /&gt;public static void Copy&lt;T, E&gt;(List&lt;t&gt; source, &lt;br /&gt;                                List&lt;e&gt; destination) where T : E&lt;br /&gt;&lt;br /&gt;Here I have specified that the type T must be the same type as, or a sub-type of, E. We got lucky with this. Why? Both T and E are being defined here. We were able to specify the constraint (though the C# specification discourages using E to define the constraint of T when E is being defined as well).&lt;br /&gt;&lt;br /&gt;Consider the following example, however:&lt;br /&gt;&lt;br /&gt;    public class MyList&lt;t&gt;&lt;br /&gt;    {&lt;br /&gt;        public void CopyTo(MyList&lt;t&gt; destination)&lt;br /&gt;        {&lt;br /&gt;            //…&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;I should be able to call CopyTo:&lt;br /&gt;&lt;br /&gt;MyList&lt;apple&gt; appleList = new MyList&lt;apple&gt;();&lt;br /&gt;MyList&lt;apple&gt; appleList2 = new MyList&lt;apple&gt;();&lt;br /&gt;//…&lt;br /&gt;appleList.CopyTo(appleList2);&lt;br /&gt;&lt;br /&gt;I must also be able to do this:&lt;br /&gt;&lt;br /&gt;MyList&lt;apple&gt; appleList = new MyList&lt;apple&gt;();&lt;br /&gt;MyList&lt;fruit&gt; fruitList2 = new MyList&lt;fruit&gt;();&lt;br /&gt;//…&lt;br /&gt;appleList.CopyTo(fruitList2);&lt;br /&gt;&lt;br /&gt;This, of course, will not work. How can we fix this? We need to say that the argument to CopyTo() can be either MyList of some type or MyList of the base type of that type. However, the constraints do not allow us to specify the base type. How about the following?&lt;br /&gt;&lt;br /&gt;public void CopyTo&lt;e&gt;(MyList&lt;e&gt; destination) where T : E&lt;br /&gt;Sorry, this does not work. It gives a compilation error that:&lt;br /&gt;&lt;br /&gt;Error 1 'TestApp.MyList&lt;t&gt;.CopyTo&lt;e&gt;()' does not define type &lt;br /&gt;parameter 'T'&lt;br /&gt;Of course, you may write the code to accept MyList of any arbitrary type and then within your code, you may verify that the type is one of acceptable type. However, this pushes the checking to runtime, losing the benefit of compile-time type safety.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;Generics in .NET 2.0 are very powerful. They allow you to write code without committing to a particular type, yet your code can enjoy type safety. Generics are implemented in such a way as to provide good performance and avoid code bloat. While there is the drawback of constraints' inability to specify that a type must be a base type of another type, the constraints mechanism gives you the flexibility to write code with a greater degree of freedom than sticking with the least-common-denominator capability of all types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-5390998498310853618?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/5390998498310853618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=5390998498310853618' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/5390998498310853618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/5390998498310853618'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-generics.html' title='.NET Generics'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_xmdzLHNex7Q/SFZBXUJbnRI/AAAAAAAAAHU/FB-wX58CCj0/s72-c/fig1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-4037445767269095293</id><published>2008-06-11T23:53:00.000-07:00</published><updated>2008-12-09T16:00:17.152-08:00</updated><title type='text'>.NET Web Services</title><content type='html'>&lt;strong&gt;Creating a .NET Web Service&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Microsoft .NET marketing has created a huge hype about its Web Services. This is the first of two articles on Web Services. Here we will create a .NET Web Service using C#. We will look closely at the Discovery protocol, UDDI, and the future of the Web Services. In the next article, we will concentrate on consuming existing Web Services on multiple platforms (i.e., Web, WAP-enabled mobile phones, and windows applications). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why do we need Web Services?&lt;/strong&gt; &lt;br /&gt;After buying something over the Internet, you may have wondered about the delivery status. Calling the delivery company consumes your time, and it's also not a value-added activity for the delivery company. To eliminate this scenario the delivery company needs to expose the delivery information without compromising its security. Enterprise security architecture can be very sophisticated. What if we can just use port 80 (the Web server port) and expose the information through the Web server? Still, we have to build a whole new Web application to extract data from the core business applications. This will cost the delivery company money. All the company wants is to expose the delivery status and concentrate on its core business. This is where Web Services come in. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a Web Service? &lt;/strong&gt;&lt;br /&gt;Web Services are a very general model for building applications and can be implemented for any operation system that supports communication over the Internet. Web Services use the best of component-based development and the Web. Component-base object models like Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), and Internet Inter-Orb Protocol (IIOP) have been around for some time. Unfortunately all these models depend on an object-model-specific protocol. Web Services extend these models a bit further to communicate with the Simple Object Access Protocol (SOAP) and Extensible Markup Language (XML) to eradicate the object-model-specific protocol barrier (see Figure 1). &lt;br /&gt;&lt;br /&gt;Web Services basically uses Hypertext Transfer Protocol (HTTP) and SOAP to make business data available on the Web. It exposes the business objects (COM objects, Java Beans, etc.) to SOAP calls over HTTP and executes remote function calls. The Web Service consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDLFDgaSXI/AAAAAAAAAF0/lcf6uKZvsLY/s1600-h/010427_1.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDLFDgaSXI/AAAAAAAAAF0/lcf6uKZvsLY/s320/010427_1.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5210888056568695154" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1. SOAP calls are remote function calls that invoke method executions on Web Service components at Location B. The output is rendered as XML and passed back to the user at Location A. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How is the user at Location A aware of the semantics of the Web Service at Location B? This question is answered by conforming to a common standard. Service Description Language (SDL), SOAP Contract Language (SCL) and Network Accessible Specification Language (NASSL) are some XML-like languages built for this purpose. However, IBM and Microsoft recently agreed on the Web Service Description Language (WSDL) as the Web Service standard. &lt;br /&gt;&lt;br /&gt;The structure of the Web Service components is exposed using this Web Service Description Language. WSDL 1.1 is a XML document describing the attributes and interfaces of the Web Service. The new specification is available at msdn.microsoft.com/xml/general/wsdl.asp. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The task ahead &lt;/strong&gt;&lt;br /&gt;The best way to learn about Web Services is to create one. We all are familiar with stock quote services. The NASDAQ, Dow Jones, and Australian Stock Exchange are famous examples. All of them provide an interface to enter a company code and receive the latest stock price. We will try to replicate the same functionality. &lt;br /&gt;&lt;br /&gt;The input parameters for our securities Web service will be a company code. The Web service will extract the price feed by executing middle-tier business logic functions. The business logic functions are kept to a bare minimum to concentrate on the Web service features. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Tools to create a Web Service &lt;/strong&gt;&lt;br /&gt;The core software component to implement this application will be MS .NET Framework SDK, which is currently in beta. You can download a version from Microsoft. I used Windows 2000 Advance Server on a Pentium III with 300 MB of RAM. &lt;br /&gt;&lt;br /&gt;The preferred Integration Development Environment (IDE) to create Web Services is Visual Studio .NET. However, you can easily use any text editor (WordPad, Notepad, Visual Studio 6.0) to create a Web Service file. &lt;br /&gt;&lt;br /&gt;I assume you are familiar with the following concepts: &lt;br /&gt;&lt;br /&gt;Basic knowledge of .NET platform &lt;br /&gt;Basic knowledge of C# &lt;br /&gt;Basic knowledge of object-oriented concepts &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a Web Service &lt;/strong&gt;&lt;br /&gt;We are going to use C# to create a Web Service called "SecurityWebService." A Web Service file will have an .ASMX file extension. (as opposed to an .ASPX file extension of a ASP.NET file). The first line of the file will look like &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDf8CKtxLI/AAAAAAAAAGk/y8v9rCX6ch4/s1600-h/4.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDf8CKtxLI/AAAAAAAAAGk/y8v9rCX6ch4/s320/4.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5210910991334622386" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This line will instruct the compiler to run on Web Service mode and the name of the C# class. We also need to access the Web Service namespace. It is also a good practice to add a reference to the System namespace. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;using System;&lt;br /&gt;using System.Web.Services;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The SecurityWebService class should inherit the functionality of the Web Services class. Therefore, we put the following line of code: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;public class SecurityWebService : WebService&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now we can use our object-oriented programming skills to build a class. C# classes are very similar to C++ or Java classes. It will be a walk in the park to create a C# class for anyone with either language-coding skills. &lt;br /&gt;&lt;br /&gt;Dot-net Web Services are intelligent enough to cast basic data types. Therefore, if we return "int," "float," or "string" data types, it can convert them to standard XML output. Unfortunately, in most cases we need get a collection of data regarding a single entity. Let's take an example. &lt;br /&gt;&lt;br /&gt;Our SecurityWebService stock quotes service requires the user to enter a company code, and it will deliver the full company name and the current stock price. Therefore, we have three pieces of information for a single company: &lt;br /&gt;&lt;br /&gt;Company code (data type - string) &lt;br /&gt;Company name (data type - string) &lt;br /&gt;Price (data type - Double) &lt;br /&gt;&lt;br /&gt;We need to extract all this data when we are referring to a single stock quote. There are several ways of doing this. The best way could be to bundle them in an enumerated data type. We can use "structs" in C# to do this, which is very similar to C++ structs. &lt;br /&gt;&lt;br /&gt;public struct SecurityInfo&lt;br /&gt; {&lt;br /&gt;  public string Code;&lt;br /&gt;  public string CompanyName;&lt;br /&gt;  public double Price;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;Now we have all the building blocks to create our Web Service. Therefore, our code will look like. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDf8CKtxLI/AAAAAAAAAGk/y8v9rCX6ch4/s1600-h/4.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDf8CKtxLI/AAAAAAAAAGk/y8v9rCX6ch4/s320/4.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5210910991334622386" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Services;&lt;br /&gt;&lt;br /&gt;public struct SecurityInfo&lt;br /&gt;{&lt;br /&gt; public string Code;&lt;br /&gt; public string CompanyName;&lt;br /&gt; public double Price;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class SecurityWebService : WebService&lt;br /&gt;{&lt;br /&gt; private SecurityInfo Security;&lt;br /&gt; &lt;br /&gt; public SecurityWebService()&lt;br /&gt; {&lt;br /&gt;  Security.Code = "";&lt;br /&gt;  Security.CompanyName = "";&lt;br /&gt;  Security.Price = 0;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void AssignValues(string Code)&lt;br /&gt; {&lt;br /&gt;  // This is where you use your business components. &lt;br /&gt;  // Method calls on Business components are used to populate the data.&lt;br /&gt;  // For demonstration purposes, I will add a string to the Code and&lt;br /&gt;  //  use a random number generator to create the price feed.&lt;br /&gt;     &lt;br /&gt;  Security.Code = Code;&lt;br /&gt;  Security.CompanyName = Code + " Pty Ltd";&lt;br /&gt;  Random RandomNumber = new System.Random();&lt;br /&gt;  Security.Price = double.Parse(new System.Random(RandomNumber.Next(1,10)).NextDouble().ToString("##.##"));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    [WebMethod(Description="This method call will get the company name and the price for a given security code.",EnableSession=false)]&lt;br /&gt; public SecurityInfo GetSecurityInfo(string Code)&lt;br /&gt; {&lt;br /&gt;  AssignValues(Code);&lt;br /&gt;  SecurityInfo SecurityDetails = new SecurityInfo();&lt;br /&gt;  SecurityDetails.Code = Security.Code;&lt;br /&gt;  SecurityDetails.CompanyName = Security.CompanyName;&lt;br /&gt;  SecurityDetails.Price = Security.Price;&lt;br /&gt;  return  SecurityDetails;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Remember, this Web Service can be accessed through HTTP for any use. We may be referring to sensitive business data in the code and wouldn't want it to fall into the wrong hands. The solution is to protect the business logic function and only have access to the presentation functions. This is achieved by using the keyword "[Web Method]" in C#. Let's look at the function headers of our code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[WebMethod(Description="This......",EnableSession=false)]&lt;br /&gt;public SecurityInfo GetSecurityInfo(string Code)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This function is exposed to the public. The "description" tag can be used to describe the Web Service functionality. Since we will not be storing any session data, we will disable the session state. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;private void AssignValues(string Code)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is a business logic function that should not be publicly available. We do not want our sensitive business information publicly available on the Web. (Note:- Even if you change the "private" keyword to "public," it will still not be publicly available. You guessed it, the keyword "[Web Method]" is not used.) &lt;br /&gt;&lt;br /&gt;We can use the business logic in this function to get the newest stock price quote. For the purpose of this article I have added some text to the company code to create the company name. The price value is generated using a random number generator.&lt;br /&gt; &lt;br /&gt;We may save this file as "SampleService.asmx" under an Internet Information Service (IIS)-controlled directory. I have saved it under a virtual directory called "/work/aspx." I'll bring it up on a Web browser. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_xmdzLHNex7Q/SFDLFWbbSxI/AAAAAAAAAF8/QCs2CkQFPr0/s1600-h/010427_2.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_xmdzLHNex7Q/SFDLFWbbSxI/AAAAAAAAAF8/QCs2CkQFPr0/s320/010427_2.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5210888061648063250" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is a Web page rendered by the .NET Framework. We did not create this page. (The page is generated automatically by the system. I did not write any code to render it on the browser. This graphic is a by-product of the previous code.) This ready-to-use functionality is quite adequate for a simple Web Service. The presentation of this page can be changed very easily by using ASP.NET pagelets and config.web files. A very good example can be found at http://www.ibuyspy.com/store/InstantOrder.asmx.&lt;br /&gt; &lt;br /&gt;Notice a link to "SDL Contract." (Even if we are using WSDL, .NET Beta still refers to SDL. Hopefully this will be rectified in the next version). This is the description of the Web Service to create a proxy object. (I will explain this in the next article.) This basically gives an overview of the Web Service and it's public interface. If you look closely, you will only see the "Web-only" methods being illustrated. All the private functions and attributes are not described in the SDL contract. The SDL contract for the SecurityWebService can be found in Appendix A. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do we use a Web Service? &lt;/strong&gt;&lt;br /&gt;Now we can use this Web Service. Let's enter some values to get a bogus price feed. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDLFgwLKtI/AAAAAAAAAGE/apOWy8vU808/s1600-h/010427_3.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDLFgwLKtI/AAAAAAAAAGE/apOWy8vU808/s320/010427_3.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5210888064419441362" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;By clicking the Invoke button a new window will appear with the following XML document &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDLFyR7BsI/AAAAAAAAAGM/rkRVdHODedk/s1600-h/010427_4.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDLFyR7BsI/AAAAAAAAAGM/rkRVdHODedk/s320/010427_4.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5210888069124392642" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is how the Web Service releases information. We need to write clients to extract the information from the XML document. Theses clients could be &lt;br /&gt;&lt;br /&gt;A Web page &lt;br /&gt;A console / Windows application &lt;br /&gt;A Wireless Markup Language (WML) / WMLScript to interact with mobile phones &lt;br /&gt;A Palm / Win CE application to use on Personal Digital Assistants (PDAs). &lt;br /&gt;&lt;br /&gt;You can also call the Web Service directly using the HTTP GET method. In this case we will not be going through the above Web page and clicking the Invoke button. The syntax for directly calling the Web Service using HTTP GET is &lt;br /&gt;&lt;br /&gt;http://server/webServiceName.asmx/functionName?parameter=parameterValue&lt;br /&gt; &lt;br /&gt;Therefore, the call for our Web Service will be &lt;br /&gt;&lt;br /&gt;http://localhost/work/aspx/SampleService.asmx/GetSecurityInfo?Code=IBM &lt;br /&gt;&lt;br /&gt;This will produce the same result as clicking the Invoke button. &lt;br /&gt;&lt;br /&gt;Now we know how to create a Web Service and use it. But the work is half done. How will our clients find our Web Service? Is there any way to search for our Web Service on the Internet? Is there a Web crawler or a Yahoo search engine for Web Services? In order to answer these questions we need to create a "discovery" file for our Web Service. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a Discovery file &lt;/strong&gt;&lt;br /&gt;Web Service discovery is the process of locating and interrogating Web Service descriptions, which is a preliminary step for accessing a Web Service. It is through the discovery process that Web Service clients learn that a Web Service exists, what its capabilities are, and how to properly interact with it. Discovery file is a XML document with a .DISCO extension. It is not compulsory to create a discovery file for each Web Service. Here is a sample discovery file for our securities Web Service. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDfBCex74I/AAAAAAAAAGU/oT7iHkQFsL0/s1600-h/2.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SFDfBCex74I/AAAAAAAAAGU/oT7iHkQFsL0/s320/2.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5210909977806499714" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We can name this file "SampleService.disco" and save it to the same directory as the Web Service. If we are creating any other Web Services under the "/work/aspx" directory, it is wise to enable "dynamic discovery." Dynamic discovery will scan for all the *.DISCO files in all the subdirectories of "/work/aspx" automatically.&lt;br /&gt; &lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDfCB2WrcI/AAAAAAAAAGc/oItMuwwKs_c/s1600-h/3.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDfCB2WrcI/AAAAAAAAAGc/oItMuwwKs_c/s320/3.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5210909994816810434" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;An example of an active discovery file can be found at http://services3.xmethods.net/dotnet/default.disco. By analyzing the discovery file we can find where the Web Services reside in the system. Unfortunately both these methods require you to know the exact URL of the discovery file. If we cannot find the discovery file, we will not be able to locate the Web Services. Universal Description, Discovery, and Integration (UDDI) describes mechanisms to advertise existing Web Services. This technology is still at the infant stage. UDDI is an open, Internet-based specification designed to be the building block that will enable businesses to quickly, easily, and dynamically find and transact business with one another using their preferred applications. A reference site for UDDI is http://uddi.microsoft.com/. &lt;br /&gt;&lt;br /&gt;There have been a lot of Web Services written by developers. www.xmethods.com is one of the sites that has an index of Web Services. Some developers are building WSDL search engines to find Web Services on the Web. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Deploying a Web Service &lt;/strong&gt;&lt;br /&gt;Deploying the Web Services from development to staging or production is very simple. Similar to ASP.NET applications, just copy the .ASMX file and the .DISCO files to the appropriate directories, and you are in business. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The future of the Web Services&lt;/strong&gt; &lt;br /&gt;The future looks bright for the Web Service technology. Microsoft is not alone in the race for Web Service technology. Sun and IBM are very interested. There are SOAP toolkits available for Apache and Java Web servers. I believe Web Services needs a bit of work, especially the Web Service discovery process. It is still very primitive. &lt;br /&gt;&lt;br /&gt;On a positive note, Web Services have the potential to introduce new concepts to the Web. One I refer to as "pay per view" architecture. Similar to pay-TV, we can build Web sites that can generate revenue for each request a user sends (as opposed to a flat, monthly subscription). In order to get some data, we can sometimes pay a small fee. Commercially this could be handy for a lot of people. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Examples &lt;/strong&gt;&lt;br /&gt;Online newspaper sites can publish a 10-year-old article with a $2 "pay per view" structure. &lt;br /&gt;&lt;br /&gt;Stock market portals can itemize every user portfolio for every single stock quote and build pricing and discount structures. &lt;br /&gt;&lt;br /&gt;And the list goes on ... &lt;br /&gt;&lt;br /&gt;On a very optimistic note, Web Services can be described as the "plug and play" building blocks of enterprise Business to Business (B2B) Web solutions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--------------------------------  Part II ------------------------------&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Asynchronous Web Services for Visual Basic .NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Asynchronous Web Services rely on the basic asynchronous behavior built into .NET; it is part of the multithreading model of .NET. The basic idea is that you can invoke a Web Method asynchronously, which means it returns before it has finished the computation, and the Web Service will tell you at a later time when it has finished. Collectively, all of this technology relies on the CodeDOM, multithreading, SOAP, HTTP, and delegates, which illustrates why a well-architected platform is essential. Fortunately, .NET is designed so that you don't really have to master any of these technologies to use asynchronous Web Services. The hardest thing you have to learn to do is to use delegates.&lt;br /&gt;&lt;br /&gt;When you are finished reading this article you will have the basic information necessary to invoke Web Methods asynchronously. We'll use a basic Web Service that returns simple data, pretending the process is long enough to warrant an asynchronous call. In July 19th's article, I wrote about calculating prime numbers. I will use a Web Service based on the ability to calculate prime numbers, returning a Boolean to indicate prime-ness.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Integrating a Web Service into Your Application&lt;/strong&gt;&lt;br /&gt;The basic steps for integrating a Web Service are reviewed in the numbered-list that follows for convenience.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Create the solution for you client application &lt;/strong&gt;&lt;br /&gt;Use UDDI to find a Web Service (or you can use a known Web Service) &lt;br /&gt;Select Project|Add Web Reference, entering the URL for the Web Service in the Address bar. (This process is just like browsing in internet explorer) &lt;br /&gt;When you have navigated to the URL of the Web Service, the Add Web Reference button should be enabled in the Add Reference dialog. Click Add Reference &lt;br /&gt;After you have selected the .asmx file representing the Web Service and added the reference, a new entry will be added to your project in the Web References folder. The folder name will be Web References (see figure 1) and a namespace, representing the Web Service host will be added to that namespace. There will be three files with the extensions .map, .disco, and .wsdl. Collectively, this information points at our Web Service.&lt;br /&gt;&lt;br /&gt;There is one other file that was added to the Web References folder that doesn't show up in the Server Explorer, Reference.vb. Reference.vb contains a proxy class that inherits from System.Web.Services.Protocols.SoapHttpClientProtocol; this class is a proxy-or wrapper-for the Web Service. The proxy class is generated using the .NET CodeDOM technology and is responsible for marshalling calls between your application and the Web Service, making Web Services easier to use.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Tip:&lt;/strong&gt; To obtain a Web Service description you can type the URL followed by the query WSDL. For example, on my machine I can obtain a Web Service description of the Primes service by typing http://localhost/primes/service1.asmx?wsdl in the Address bar of Internet Explorer.&lt;br /&gt;Importantly, the proxy class contains three methods for every Web Method. One is a proxy for the synchronous version of the Web Method, and the other two are proxy methods for the SoapHttpClientProtocol.BeginInvoke and SoapHttpClientProtocol.EndInvoke. That is, the second pair of methods represents proxies for asynchronous invocation of the Web Service.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Invoking a Web Method Asynchronously&lt;/strong&gt;&lt;br /&gt;We can figure out how to invoke the Web Service asynchronously by examining the proxy methods. Listing 1 shows the proxy methods for the Web Method IsPrime.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Listing 1: Asynchronous proxy methods for the Web Method IsPrime.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Public Function BeginIsPrime(ByVal number As Long, _&lt;br /&gt;  ByVal callback As System.AsyncCallback, _&lt;br /&gt;  ByVal asyncState As Object) As System.IAsyncResult&lt;br /&gt;&lt;br /&gt;  Return Me.BeginInvoke("IsPrime", New Object() {number}, _&lt;br /&gt;    callback, asyncState)&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;        &lt;br /&gt;Public Function EndIsPrime( _&lt;br /&gt;  ByVal asyncResult As System.IAsyncResult) As Boolean&lt;br /&gt;  &lt;br /&gt;  Dim results() As Object = Me.EndInvoke(asyncResult)&lt;br /&gt;  Return CType(results(0),Boolean)&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;As the name suggests we call BeginIsPrime to initiate the asynchronous call. The proxy for BeginInvoke is a function that returns an interface IAsyncResult. The return value is used to synchronize interaction between the client and the Web Service. The first parameter is the value we pass to the Web Service; in this instance it is the number that we want to check for prime-ness. The second parameter is the callback. The second parameter will be the address of the method we want the Web Service to invoke when the Web Method has finished processing. The type of the callback method is the delegate AsyncCallback. The third argument is any additional object we want to pass through to the Web Service and the callback method. The third parameter can be used for any additional information, including simple data or objects.&lt;br /&gt;&lt;br /&gt;The second method is called when the Web Service is ready or to block in the client until the Web Service is ready. For example, you can call the EndInvoke proxy in the callback method when the Web Service calls it. The callback is defined such that it accepts, and will receive, an IAsyncResult argument that you pass back to the EndInvoke proxy. The IAsyncResult object is used to synchronize the data exchange between the client and Web Service.&lt;br /&gt;&lt;br /&gt;Listing 2 provides a slim example that combines all of the elements together. After the listing is an overview of the code as I wrote it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Listing 2: Invoking a Web Method asynchronously.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1:  Imports System.Console&lt;br /&gt;2:  Imports System.Threading&lt;br /&gt;3:&lt;br /&gt;4:  Public Class Form1&lt;br /&gt;5:    Inherits System.Windows.Forms.Form&lt;br /&gt;6:&lt;br /&gt;7:  [ Windows Form Designer generated code ]&lt;br /&gt;8:&lt;br /&gt;9:    Private Sub Button1_Click(ByVal sender As System.Object, _&lt;br /&gt;10:     ByVal e As System.EventArgs) Handles Button1.Click&lt;br /&gt;11:&lt;br /&gt;12:     ListBox1.Items.Clear()&lt;br /&gt;13:     Start()&lt;br /&gt;14:   End Sub&lt;br /&gt;15:&lt;br /&gt;16:   Private Service As localhost.Service1 = _&lt;br /&gt;17:     New localhost.Service1()&lt;br /&gt;18:   Private Sub Start()&lt;br /&gt;19:&lt;br /&gt;20:     Dim Numbers() As Long = _&lt;br /&gt;21:       New Long() {103323, 2, 3, 56771, 7}&lt;br /&gt;22:     Dim Number As Long&lt;br /&gt;23:&lt;br /&gt;24:     For Each Number In Numbers&lt;br /&gt;25:       Dim Result As IAsyncResult = _&lt;br /&gt;26:         Service.BeginIsPrime(Number, _&lt;br /&gt;27:         AddressOf Responder, Number)&lt;br /&gt;28:     Next&lt;br /&gt;29:&lt;br /&gt;30:   End Sub&lt;br /&gt;31:&lt;br /&gt;32:   Private Sub Responder(ByVal Result As IAsyncResult)&lt;br /&gt;33:&lt;br /&gt;34:     Dim IsPrime As Boolean = Service.EndIsPrime(Result)&lt;br /&gt;35:&lt;br /&gt;36:     If (InvokeRequired) Then&lt;br /&gt;37:       Invoke(New MyDelegate(AddressOf AddToList), _&lt;br /&gt;38:         New Object() {IsPrime, _&lt;br /&gt;39:         CType(Result.AsyncState, Long)})&lt;br /&gt;40:     End If&lt;br /&gt;41:&lt;br /&gt;42:   End Sub&lt;br /&gt;43:&lt;br /&gt;44:   Private Delegate Sub MyDelegate( _&lt;br /&gt;45:     ByVal IsPrime As Boolean, ByVal Number As Long)&lt;br /&gt;46:&lt;br /&gt;47:   Private Sub AddToList(_&lt;br /&gt;48:     ByVal IsPrime As Boolean, ByVal Number As Long)&lt;br /&gt;49:&lt;br /&gt;50:     Const Mask As String = _&lt;br /&gt;51:       "{0} {1} a prime number"&lt;br /&gt;52:&lt;br /&gt;53:     Dim Filler() As String = New String() {"is not", "is"}&lt;br /&gt;54:     ListBox1.Items.Add( _&lt;br /&gt;55:       String.Format(Mask, Number, _&lt;br /&gt;56:     Filler(Convert.ToInt16(IsPrime))))&lt;br /&gt;57:&lt;br /&gt;58:   End Sub&lt;br /&gt;59:&lt;br /&gt;60: End Class&lt;br /&gt;&lt;br /&gt;(The code generated by the designer is condensed-simulating Code Outlining in Visual Studio .NET-on line 7.) The basic idea is that the consumer sends several inquiries about possible prime numbers. Large prime numbers take longer to calculate than prime numbers; so the client application is designed to send every number asynchronously rather than get bogged down on big prime candidates.&lt;br /&gt;&lt;br /&gt;The process is initiated in the Button1_Click event on line 13 when Start is invoked. (The actual application sends the same numbers ever time, but you could easily make this dynamic, too.) &lt;br /&gt;&lt;br /&gt;Start is defined on lines 18 through 30 in listing 1. An array of candidate numbers is created on lines 20 and 21, demonstrating inline initialization in Visual Basic .NET. As you can see the largest number is first. In a synchronous application the remaining numbers would wait in line until 103323 was evaluated. In our model all requests will be sent and the results displayed as they are available. The For Each loop manages sending every number to be processed, representing ongoing work while preceding requests are being serviced by the Web Service.&lt;br /&gt;&lt;br /&gt;The code we are interested in is on lines 25 through 27. Line 25 shows you how to obtain an IAsyncResult object in case we elect to block in the Start method. (We won't.) The first argument is the Number to be evaluated by the Web Method IsPrime; the second argument is the delegate, created implicitly with the AddressOf operator, and the third argument is the Number. I passed the Number a second time for display purposes (refer to line 55). The Web Service was created on lines 16 and 17, before the Form's constructor was called. The name localhost represents a namespace in this context and happens to be derived from the Web Service host computer.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Retrieving the Results from the Web Method&lt;/strong&gt;&lt;br /&gt;There are several ways to block while you are waiting for a Web Service to return. You can use the IAsyncResult.IsCompleted property in a loop, call Service.EndIsPrime-the EndInvoke proxy-or request theIAsyncResult.AsyncWaitHandle. In our example, we process merrily until the callback is invoked by the Web Service. The callback method is defined on lines 32 through 42. When the callback is called we can obtain the result by calling the EndInvoke proxy method as demonstrated on line 34.&lt;br /&gt;&lt;br /&gt;Lines 36 through 40 and 44 through 58 exist in this instance due to the kind of application—a Windows Form application. When you invoke a Web Service asynchronously the callback method will be called back on a different thread than the one the Windows Forms controls reside on. As Windows Forms is not thread-safe-which means you should interact with Windows Forms controls on the same thread as the one they live on-we can use the Control.Invoke method and push the "work" onto the same thread that the control lives on. Again we use delegates to represent the work to be done.&lt;br /&gt;&lt;br /&gt;The method InvokeRequired can be used to determine if you need to call invoke, as demonstrated on line 36. Lines 37, 38, and 39 demonstrate the Invoke method. Define a new delegate based on the signature of the procedure you want to Invoke. Create an instance of that delegate type, initializing the delegate with the address of your work procedure. Pass an array of objects matching the parameters your work-method needs. The delegate is defined on lines 44 and 45. An instance of the delegate is created on line 37, and the array of arguments is demonstrated on lines 38 and 39. Lines 38 and 39 create an array of Object inline passing a Boolean and a Long as is expected by the AddToList method. Pay attention to the fact that the delegate signature, the procedure used to initialize the delegate, and the arguments passed to the delegate all of have identical footprints.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br /&gt;Asynchronous Web Services depend on a lot of advanced aspects of the .NET framework, including SOAP, XML, HTTP, CodeDOM, TCP/IP, WDSL, UDDI, multithreading, and delegates, to name a view. Fortunately, these technologies exist already and work on our behalf behind the scenes for the most part. If you want to use asynchronous Web Services, the hardest thing you need to master are delegates.&lt;br /&gt;&lt;br /&gt;Don't let anyone trivialize Web Services. They are powerful and complicated, but the complicated part was codified by Microsoft. The end result is that Web Services are easy to consume, with only modest additional complexity to invoke them asynchronously. &lt;br /&gt;&lt;br /&gt;Asynchronous Web Services will add some zip to your applications. Be mindful of the existence of more than one thread and you are all set.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-4037445767269095293?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/4037445767269095293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=4037445767269095293' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/4037445767269095293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/4037445767269095293'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-web-services.html' title='.NET Web Services'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_xmdzLHNex7Q/SFDLFDgaSXI/AAAAAAAAAF0/lcf6uKZvsLY/s72-c/010427_1.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-4388564849645597449</id><published>2008-06-11T03:08:00.000-07:00</published><updated>2008-12-09T16:00:17.443-08:00</updated><title type='text'>.NET Windows Services</title><content type='html'>&lt;strong&gt;Introduction &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Windows Services are long running executable applications that have no User Interface, can be configured to start automatically and can also be started manually. Windows services are not meant to interact with users and should not have a user interface. These applications are actually controlled by the Service Control Manager. This article discusses Windows Services and shows how we can implement a simple Windows Service in C#.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are Windows Services? &lt;/strong&gt;&lt;br /&gt;Windows services are long running executable applications that typically do not possess any user interface, are controlled by the Service Control Manager (SCM) and can even be configured to start automatically after the system boots. They typically execute in their own windows sessions. They can execute even if the user has not logged in to the system. They can even be started, paused, re-started manually. These applications are somewhat similar to the daemon processes of UNIX in the sense that they remain dormant most of the time and execute in the background as and when needed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why are Windows Services needed? &lt;/strong&gt;&lt;br /&gt;The following are the benefits of using Windows Services:&lt;br /&gt;&lt;br /&gt;· Network connection management&lt;br /&gt;· Disk access monitoring&lt;br /&gt;· Security control of application&lt;br /&gt;· Log messages related to the application's requirements&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Anatomy of a Windows Service Application &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This section briefly discusses the anatomy of a Windows Service application. The .NET Framework's System.ServiceProcess.ServiceBase encapsulates the entire functionality that is required to create and control Windows Service applications. &lt;br /&gt;The following two classes are required for implementing a Windows Service: &lt;br /&gt;&lt;br /&gt;· &lt;strong&gt;System.ServiceProcess.ServiceBase &lt;/strong&gt;&lt;br /&gt;· &lt;strong&gt;System.Configuration.Install.Installer&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The ServiceBase class must be inherited by your Service class to specify your Service and the Installer class should be inherited in your Installer class to specify the Service installer. &lt;br /&gt;&lt;br /&gt;The following are the methods of ServiceBase class.&lt;br /&gt;· OnStart&lt;br /&gt;· OnStop&lt;br /&gt;· OnPause&lt;br /&gt;· OnContinue&lt;br /&gt;· OnShutdown&lt;br /&gt;· OnPowerEvent&lt;br /&gt;· OnCustomCommand&lt;br /&gt;&lt;br /&gt;The following section discusses these methods briefly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnStart:&lt;/strong&gt; This method is fired when the service is started by the Service Control Manager. It should be noted that this method is called only once during the life cycle. This method is used to specify the processing that occurs when a Start command is received. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnStop:&lt;/strong&gt; This method is called when the service is stopped by the Service Control Manager. This is typically used to specify the processing that occurs when a Stop command is received by the Service Control Manager. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnPause:&lt;/strong&gt; This method is called when the service is paused and typically contains the processing for pausing the service.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnContinue:&lt;/strong&gt; This method is called when the service is resumed after being paused. This method typically contains the necessary processing so as to enable a service to return to normal functioning after the same was paused earlier.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnShutDown:&lt;/strong&gt; This method is called when the system is being shutdown and contains the necessary processing indicative of what should happen prior to the system shutting down.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnPowerEvent:&lt;/strong&gt; This method is used to specify the necessary processing that should take place when the power status changes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;OnCustomCommand:&lt;/strong&gt; This method is used to specify a custom command, i.e., any command other than those discussed above. &lt;br /&gt;&lt;br /&gt;In addition to the above methods, the System.ServiceProcess.ServiceBase class also contains the following properties:&lt;br /&gt;· AutoLog&lt;br /&gt;· CanPauseAndContinue&lt;br /&gt;· CanShutdown&lt;br /&gt;· CanStop&lt;br /&gt;· ServiceName&lt;br /&gt;&lt;br /&gt;The following section discusses these properties briefly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CanStop:&lt;/strong&gt; This is a boolean property that is true if the service can be stopped, false otherwise.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CanShutdown:&lt;/strong&gt; This is a boolean property that is true if the service wants to be notified that the system on which it is being executed is being shutdown, false otherwise.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CanPauseAndContinue:&lt;/strong&gt; This is a boolean property that is true if the service can be paused and then restarted, false otherwise.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CanHandlePowerEvent:&lt;/strong&gt; This is a boolean property that is set to true if the service should be notified of a change in the power status of the system on which the service is being executed. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;AutoLog:&lt;/strong&gt; This is a boolean property that is set to true if the service should write events to the Application Event Log when any action is performed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Implementing a Simple Windows Service Application in .NET &lt;/strong&gt;&lt;br /&gt;This section makes use of the concepts learned so far and shows how we can implement a simple Windows Service in .NET.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating the Windows Service&lt;/strong&gt;&lt;br /&gt;To create a new project in Visual Studio .NET 2003, select C# as the language of your choice and then select Windows Service as the project. Specify the name of the project and save the same. Note that when implementing a Windows Service, you should have two classes, one is the Service class and the other is the Service Controller class. Refer to the following listings that contain the source code for both the custom Service and the custom ServiceController classes.&lt;br /&gt;&lt;br /&gt;Listing 1: The Sample Windows Service Class&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;using System.ServiceProcess;&lt;br /&gt;using System.IO;&lt;br /&gt; &lt;br /&gt;namespace SampleWindowsService&lt;br /&gt;{&lt;br /&gt;  public class SampleWindowsService: System.ServiceProcess.ServiceBase&lt;br /&gt;  {&lt;br /&gt;    StreamWriter streamWriter;&lt;br /&gt;    private System.ComponentModel.Container components = null;&lt;br /&gt;    public SampleWindowsService()&lt;br /&gt;    {&lt;br /&gt;      InitializeComponent();&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;      System.ServiceProcess.ServiceBase[]ServicesToRun;&lt;br /&gt;      ServicesToRun = new System.ServiceProcess.ServiceBase[]&lt;br /&gt;      {&lt;br /&gt;        new SampleWindowsService()&lt;br /&gt;      };&lt;br /&gt;      System.ServiceProcess.ServiceBase.Run(ServicesToRun);&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;    private void InitializeComponent()&lt;br /&gt;    {&lt;br /&gt;      components = new System.ComponentModel.Container();&lt;br /&gt;      this.ServiceName = "Sample Service";&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;    protected override void Dispose(bool disposing)&lt;br /&gt;    {&lt;br /&gt;      if (disposing)&lt;br /&gt;      {&lt;br /&gt;        if (components != null)&lt;br /&gt;        {&lt;br /&gt;          components.Dispose();&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      base.Dispose(disposing);&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    protected override void OnStart(string[]args)&lt;br /&gt;    {&lt;br /&gt;      streamWriter = new StreamWriter(new FileStream(&lt;br /&gt;        "C:\\SampleWindowsServiceLogger.txt", System.IO.FileMode.Append));&lt;br /&gt;      this.streamWriter.WriteLine("Starting Sample Windows Service at " +&lt;br /&gt;        DateTime.Now.ToString());&lt;br /&gt;      this.streamWriter.Flush();&lt;br /&gt;      this.streamWriter.Close();&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    protected override void OnStop()&lt;br /&gt;    {&lt;br /&gt;      streamWriter = new StreamWriter(new FileStream(&lt;br /&gt;        "C:\\SampleWindowsServiceLogger.txt", System.IO.FileMode.Append));&lt;br /&gt;      this.streamWriter.WriteLine("Stopping Sample Windows Service at " +&lt;br /&gt;        DateTime.Now.ToString());&lt;br /&gt;      this.streamWriter.Flush();&lt;br /&gt;      this.streamWriter.Close();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Listing 2: The Sample Windows Service Installer Class&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.ServiceProcess;&lt;br /&gt;using System.Configuration.Install;&lt;br /&gt; &lt;br /&gt;namespace SampleWindowsService&lt;br /&gt;{&lt;br /&gt;  [RunInstaller(true)]&lt;br /&gt;  public class SampleWindowsServiceInstaller:&lt;br /&gt;    System.Configuration.Install.Installer&lt;br /&gt;  {&lt;br /&gt; &lt;br /&gt;    private System.ComponentModel.Container components = null;&lt;br /&gt; &lt;br /&gt;    public SampleWindowsServiceInstaller()&lt;br /&gt;    {&lt;br /&gt;      InitializeComponent();&lt;br /&gt;      ServiceProcessInstaller spi = new ServiceProcessInstaller();&lt;br /&gt;      ServiceInstaller si = new ServiceInstaller();&lt;br /&gt;      si.DisplayName = "Sample Windows Service";&lt;br /&gt;      si.ServiceName = "Sample Windows Service";&lt;br /&gt;      si.StartType = ServiceStartMode.Automatic;&lt;br /&gt;      this.Installers.Add(si);&lt;br /&gt; &lt;br /&gt;      spi.Account = ServiceAccount.LocalSystem;&lt;br /&gt;      spi.Username = null;&lt;br /&gt;      spi.Password = null;&lt;br /&gt;      this.Installers.Add(spi);&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    protected override void Dispose(bool disposing)&lt;br /&gt;    {&lt;br /&gt;      if (disposing)&lt;br /&gt;      {&lt;br /&gt;        if (components != null)&lt;br /&gt;        {&lt;br /&gt;          components.Dispose();&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      base.Dispose(disposing);&lt;br /&gt;    }&lt;br /&gt;    private void InitializeComponent()&lt;br /&gt;    {&lt;br /&gt;      components = new System.ComponentModel.Container();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The Windows Service implemented in this article stores the time of starting, stopping or resuming the service in a file C:\\SampleWindowsServiceLogger.txt in the local file system. Make changes to implement the service that can suit your needs.&lt;br /&gt;Start, stop and resume the Windows Service&lt;br /&gt;&lt;br /&gt;Go to Control Panel | Administrative Tools | Computer Management and select the Services and Applications tab. Then locate your installed service and click on Start to start the service. The rest is self explanatory.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Installing the Windows Service&lt;/strong&gt;&lt;br /&gt;In order to install the Windows Service implemented above, use the installutil .NET Framework command line utility. Specify the following at the command prompt.&lt;br /&gt;&lt;strong&gt;Installutil SampleWindowsServiceInstaller.exe&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Un-Installing the Windows Service&lt;/strong&gt;&lt;br /&gt;In order to uninstall the Windows service, specify the following at the command prompt:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Installutil /u SampleWindowsServiceInstaller.exe&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Important Points &lt;/strong&gt;&lt;br /&gt;You should note that a Microsoft .NET service will not start if the application event log is full. Hence, it is recommended to clear the event log down and set to overwrite as needed. Remember inheriting the ServiceBase class to create you Service class and the System.Configuration.Install.Installer class when implementing your Service Controller class.&lt;br /&gt;&lt;br /&gt;----------------------          Part II      -----------------------&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Windows Services Defined &lt;/strong&gt;&lt;br /&gt;Every time a user logs on the NT machine, a desktop is immediately assigned to him. Any process or thread started by the user is attached to this desktop. Multiple desktops can exist, but only one desktop can be active at a time. These desktops each have threads assigned to them. Windows can be created in each of these threads, but only those windows in threads assigned to the active desktop are visible.&lt;br /&gt;Windows services are processes that exist without any desktops and run in the background (similar to daemon processes in UNIX). They can be started before any user logs into the system. After the operating system is initially loaded, it immediately begins loading the services that are configured to automatically start. The user can log on to the system before all automatic services are loaded, but the user is not presented with a desktop until all the automatic services have finished loading. After logging on, the user can start and stop the services. When the user logs off, the desktop is closed and all the processes assigned to his desktop are also closed. But any services that exist when the user logs off are not closed and remain alive and running. They are often loaded at boot up, before any user logs in, and are often independent of any specific user logged on at the time. In fact, a service has its own login session. A service can also be launched manually by a user. Although it’s possible, Windows Service typically has no user interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Need for Windows Services &lt;/strong&gt;&lt;br /&gt;The fact that services can exist without desktops is the advantage that makes services desirable. The various situations during which a process is installed as a service are:&lt;br /&gt;&lt;br /&gt;· When a process is needed that starts when the computer starts and stops only when computer stops&lt;br /&gt;· Hardware drivers, or applications controlling or monitoring hardware attached to a system; e.g. monitoring for plug and play devices&lt;br /&gt;· A process is required that operates even when no users are logged on to the computer; e.g. Anti Virus programs, Disk Monitoring programs etc.&lt;br /&gt;· Parts of Operating System itself; e.g. RPC (Remote Procedure Call) server, DCOM (Distributed Component Object Model) server, etc.&lt;br /&gt;· Software which handles communication from users on other machines, who have logged on to this machine; e.g. FTP Server, Web Server etc.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Service Control Manager (SCM) &lt;/strong&gt;&lt;br /&gt;Due to the fact that services have no desktops, they usually do not interact with the users. But there has to be a way for controlling and managing these services. Service Control Manager does just that.&lt;br /&gt;&lt;br /&gt;The SCM, a part of the windows kernel, is the one that controls the lifetime of the service. Any process that needs to be started and stopped like a service has to register itself with the SCM. The SCM then takes care of when to launch the service and when to stop it. The SCM holds a list of all the installed services, when they should be started, whether they should be allowed to interact with the desktop, etc.&lt;br /&gt;&lt;br /&gt;The administrator can control services by sending control requests to them (e.g. "start service", "stop service", etc.) via the SCM. This is done using the Services applet of the control panel; double-clicking on the icon brings up the Services window, which lists all the services in the SCM database. Another utility to view the services running is WinMsd.exe. Combining the functionalities available in these two utilities, with an additional capability to control and configure the services on remote computers is Service Controller (SC.exe). This utility is not pre-installed with windows and has to be downloaded to every computer that needs it. All these utilities use the SCM to communicate with the services.&lt;br /&gt;&lt;br /&gt;The SCM maintains its database of services installed in the system in the registry. Each service has an entry in the following key:&lt;br /&gt;&lt;br /&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\&lt;Service Name&gt;&lt;br /&gt;&lt;br /&gt;Here, the Service Name is the name of the service used by the SCM. The service name seen in the Services applet is different from this one. This is a unique name used internally by the SCM. The corresponding name of each service which is displayed in the applet is stored in the key Display Name inside the Service Name key.&lt;br /&gt;&lt;br /&gt;Each service can run by logging on as either a Local System or particular user account. Also the services can be enabled or disabled for specific hardware profile. Each service could either run independently or it will depend on some other service(s). The list of services each service depends on will be maintained by the SCM. All these information could be seen from the Services applet by looking at the properties of each service. Other than the list of services a particular service depends on, a list of services that depend on this service can also be seen. &lt;br /&gt;&lt;br /&gt;When a service fails, the SCM can decide what action to take. These can be specified directly through the Service applet. The possible actions are:&lt;br /&gt;&lt;br /&gt;· Restart the service&lt;br /&gt;· Run a particular file&lt;br /&gt;· Reboot the computer&lt;br /&gt;· Take no action&lt;br /&gt;&lt;br /&gt;By default the response for a failure is to take no action. If the service fails for the second time too, one of these actions can be set. For subsequent failures, another action could be assigned.&lt;br /&gt;&lt;br /&gt;Building a service is a little complicated in the sense that a certain steps have to be followed to successfully build and install a service. Prior to .NET, the only efficient way to build a .NET was by building it in C++/ VC++. It was complicated and had various issues to be considered while doing it. But .NET has changed the way the services were build. With its Framework Base Classes available as a part of the .NET Framework, building services were made easy. By taking advantage of the object oriented capability of .NET, various tasks needed to build a service has been greatly simplified by encapsulating them inside various classes and including them as a part of the .NET Framework Base Classes. These base classes in the .NET Framework take care of the system-level interfacing&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Approach to Windows Services &lt;/strong&gt;&lt;br /&gt;When .NET is used to create services, the steps involved in doing it are reduced. Much of the functionalities and system level interactions are wrapped inside classes and available as a part of the Framework Base Classes. Any .NET language can be used to create Windows Services. Two base classes needed for creating the Windows Services are &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;System.ServiceProcess.ServiceBase &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;System.Configuration.Install.Installer&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;System.ServiceProcess.ServiceBase provides the base class for the service itself. The class that inherits from this class contains the logic that runs in the service. System.Configuration.Install.Installer provides the interface necessary to get the service installed under Windows 2000 and NT. It isn't typically necessary to put any logic in the installer class. There can be more than one service in a project. The installer class creates one ServiceProcessInstaller object (which knows how to install the service with the SCM), and a ServiceInstaller object. The ServiceInstaller object writes information to the registry which is needed for installation. A subkey is added under&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In VB.NET, any project created as a service will automatically create a class that inherits from the System.ServiceProcess.ServiceBase class. But the installer class has to be included manually. A Windows Service has a special installation procedure that handles all the operating-system communications necessary to execute a service. A special command-line program in .NET named InstallUtil.exe installs and uninstalls Windows Services produced in .NET.&lt;br /&gt;&lt;br /&gt;In VB.NET, the steps that are followed to develop a Windows Service are:&lt;br /&gt;1. Create Windows Service project in Visual Basic.NET&lt;br /&gt;2. Add installer to project&lt;br /&gt;3. Add/change logic and build the executable for the service&lt;br /&gt;4. Install the service using InstallUtil.exe&lt;br /&gt;5. Start the service using the Service applet in the Control Panel&lt;br /&gt;The same applet can be used to stop the service. The InstallUtil.exe can be used again to uninstall the service. This is done by passing the ‘/u’ attribute&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Building Windows Services &lt;/strong&gt;&lt;br /&gt;A windows service exists as an executable file and may contain more than one service. The behavior of each of the service is defined by writing a class for each that inherits from the ServiceProcess.ServiceBase class and code can be added to handle various methods provided by this class. The service can provide code for OnStart, OnStop, OnPause, OnContinue, and OnShutdown methods called by the SCM as a user interacts with the service. None of these procedures are required, but they can be used to provide specific behavior in reaction to requests from the SCM’s user interface, or programmatically from other services.&lt;br /&gt;&lt;br /&gt;The steps to be taken to create windows services under .NET:&lt;br /&gt;&lt;br /&gt;1. Create a new project in .NET by choosing the ‘Windows Services’ template. The project can either be VB.NET or C#.  &lt;br /&gt;2. A class named Service1 will be created. Open the class in design view. This can be done either by pressing Shift+F7 or choose View | Designer menu item.&lt;br /&gt;3. The properties could be set as necessary. The three Boolean properties – CanPauseAndContinue, CanShutDown, and CanStop- control the behavior of the service. &lt;br /&gt;4. Add startup code. The service’s OnStart event can be used to set up the service and data structures used, and perhaps log information to the event log. Also code to handle the OnContinue, OnCustomCommand, OnPause, OnShutdown, and OnStop events. &lt;br /&gt;&lt;br /&gt;Add an Installer. This can be done by going to the service class’s design view as done in step 2. Now, clicking on the ‘Add Installer’ will add the installer classes.&lt;br /&gt;&lt;br /&gt;Once the Installer class has been added, Visual Studio .NET creates a new project file named ProjectInstaller.cs. This file contains two components:&lt;br /&gt;&lt;br /&gt; ServiceProcessInstaller1 and ServiceInstaller1. The properties of the ServiceInstaller1 class will show the service name in ServiceName property as Service1. The ServiceProcessInstaller1 has properties such as UserName and Password as shown in fig 2.0. They will be by default set to ‘Nothing.’ For the installer to be able to install the service, the account information should be supplied. For a simple service the account property of the ServiceProcessInstaller1 could be set to LocalSystem. The ServiceName property of the ServiceInstaller object should be the same name as that of the service class.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Installing Windows Services &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Once the steps needed to build the service is over, it should be installed. Following are the steps to do it.&lt;br /&gt;&lt;br /&gt;1. Save the project.&lt;br /&gt;2. Build the service’s executable file. Build | Build menu item.&lt;br /&gt;3. Open the Visual Studio .NET Command Prompt item from the start menu. It will be installed as a subitem of the Visual Studio .NET Tools item. This shortcut sets all the path necessary before going to the DOS prompt. Change the folder to the location where the executable is located. It will be found in the bin folder within the folder where the project is stored.&lt;br /&gt;4. Install the service. This can be done by using the InstallUtil tool that comes with the Visual Studio. Use the following command line:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;InstallUtil Service1.exe&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE-7MrvI4UI/AAAAAAAAAFk/GpDqcnYi4L8/s1600-h/6.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE-7MrvI4UI/AAAAAAAAAFk/GpDqcnYi4L8/s320/6.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5210589120464216386" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;5 .Start the service. This can be done by running the Windows Service Manager. In the services list, the service now installed will be listed as Service1. Right click and start the service.&lt;br /&gt;6. Now, any Startup events can be viewed by opening the Event Viewer. Select the Application log, and any entries send to the log can be seen there.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE-7NTup8TI/AAAAAAAAAFs/1jofPeetvlE/s1600-h/untitled.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE-7NTup8TI/AAAAAAAAAFs/1jofPeetvlE/s320/untitled.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5210589131199607090" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Removing and Debugging Windows Services&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Removing&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Removing the service can be done by running the same InstallUtil tool but with a /u parameter. This will uninstall the service. The entry in the Windows Service Manager will be removed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Debugging&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Because a service has to be compiled and installed before running it, debugging becomes a little more complex than the normal applications. To debug a service, we have to run it and debug the running process. The steps to follow:&lt;br /&gt;&lt;br /&gt;1. Install the service and run it. &lt;br /&gt;2. In Visual Studio, select Debug | Processes menu item. Processes dialog box is displayed. &lt;br /&gt;3. Select the Show system processes check box to include the running services.&lt;br /&gt;4. Select the Service1 entry and click Attach. Click OK to accept. Close Processes dialog box.&lt;br /&gt;5. Set the breakpoint in the code at the location to be tested.&lt;br /&gt;6. Trigger the breakpoint by taking necessary action. For example, if the breakpoint is in the OnStop procedure, stop the processes to invoke it. Now single stepping can be done. To continue F5 should be pressed.&lt;br /&gt;7. Then after the debugging is finished, detach the process by using the Debug | Processes menu. Select the service and click Detach.&lt;br /&gt;Use the Debug | Stop Debugging menu item to stop debugging session.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;As a simple example, the following code can be used to test a service. Once the steps are followed to create a service, procedures for handling the start and stop event of the service is automatically created. These events can be tested by putting a log entry. The code might look like this:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;For C# project:&lt;/strong&gt;&lt;br /&gt;protected override void OnStart(string[] args)&lt;br /&gt;{&lt;br /&gt;    EventLog.WriteEntry( String.Format("Process Starting…") );&lt;br /&gt;}&lt;br /&gt;&lt;strong&gt;For Visual Basic project:&lt;/strong&gt;&lt;br /&gt;Protected Overrides Sub OnStart(ByVal args() As String)&lt;br /&gt;EventLog.WriteEntry( String.Format("Process Starting…"))&lt;br /&gt;End Sub&lt;br /&gt;The logged entry can be viewed from the Event Viewer applet.&lt;br /&gt;&lt;br /&gt;Various Classes Available in .NET to Deal with Windows Services &lt;br /&gt;The System.ServiceProcess namespace provides classes that allow you to implement, install, and control Windows service applications. The various classes available within this namespace are:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Classes&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Class &amp; Description&lt;/strong&gt;    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ServiceBase&lt;/strong&gt;&lt;br /&gt;Provides a base class for a service that will exist as part of a service application. ServiceBase must be derived when creating a new service class.    &lt;br /&gt;&lt;strong&gt;ServiceController&lt;/strong&gt;&lt;br /&gt;Represents a Windows service and allows you to connect to a running or stopped service, manipulate it, or get information about it.    &lt;br /&gt;&lt;strong&gt;ServiceControllerPermission&lt;/strong&gt;&lt;br /&gt;Allows control of code access security permissions for service controllers.    &lt;br /&gt;&lt;strong&gt;ServiceControllerPermissionAttribute&lt;/strong&gt;&lt;br /&gt;Allows declarative service controller permission checks.    &lt;br /&gt;&lt;strong&gt;ServiceControllerPermissionEntry&lt;/strong&gt;&lt;br /&gt;Defines the smallest unit of a code access security permission that is set for a ServiceController.    &lt;br /&gt;&lt;strong&gt;ServiceControllerPermissionEntryCollection&lt;/strong&gt;&lt;br /&gt;Contains a strongly-typed collection of ServiceControllerPermissionEntry objects.   &lt;br /&gt;&lt;strong&gt;ServiceInstaller&lt;/strong&gt;&lt;br /&gt;Installs a class that extends ServiceBase to implement a service. This class is called by the install utility when installing a service application.    &lt;br /&gt;&lt;strong&gt;ServiceProcessDescriptionAttribute&lt;/strong&gt;&lt;br /&gt;Specifies a description for a property or event.    &lt;br /&gt;&lt;strong&gt;ServiceProcessInstaller&lt;/strong&gt;&lt;br /&gt;Installs an executable containing classes that extend ServiceBase. This class is called by installation utilities, such as InstallUtil.exe, when installing a service application.    &lt;br /&gt;&lt;strong&gt;TimeoutException&lt;/strong&gt;&lt;br /&gt;The exception that is thrown when a specified timeout has expired.&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;Enumerations&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Enumeration &amp;  Description&lt;/strong&gt;&lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;PowerBroadcastStatus&lt;/strong&gt;&lt;br /&gt;Indicates the system's power status.    &lt;br /&gt;&lt;strong&gt;ServiceAccount&lt;/strong&gt;&lt;br /&gt;Specifies a service's security context, which defines its logon type.&lt;br /&gt;&lt;strong&gt;ServiceControllerPermissionAccess&lt;/strong&gt;&lt;br /&gt;Defines access levels used by ServiceController permission classes.    &lt;br /&gt;&lt;strong&gt;ServiceControllerStatus&lt;/strong&gt;&lt;br /&gt;Indicates the current state of the service.    &lt;br /&gt;&lt;strong&gt;ServiceStartMode&lt;/strong&gt;&lt;br /&gt;Indicates the start mode of the service.    &lt;br /&gt;&lt;strong&gt;ServiceType&lt;/strong&gt;&lt;br /&gt;Represents the type of the service.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;By taking advantage of the Framework Base Classes, the complexity needed to create a service is greatly reduced. This lets the developer to concentrate more on the functionality of the service instead of spending time in creating it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-4388564849645597449?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/4388564849645597449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=4388564849645597449' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/4388564849645597449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/4388564849645597449'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-windows-services.html' title='.NET Windows Services'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_xmdzLHNex7Q/SE-7MrvI4UI/AAAAAAAAAFk/GpDqcnYi4L8/s72-c/6.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-8020486561213554168</id><published>2008-06-09T04:58:00.000-07:00</published><updated>2008-06-09T05:34:47.183-07:00</updated><title type='text'>.NET Remoting</title><content type='html'>&lt;strong&gt;.NET Remoting: A Technical Overview &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Contents&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Introduction&lt;br /&gt;Remote Objects&lt;br /&gt;Proxy Objects&lt;br /&gt;Channels&lt;br /&gt;Activation&lt;br /&gt;Object Lifetime with Leasing&lt;br /&gt;Conclusion&lt;br /&gt;Appendix A: Remoting Sample Using a TCP Channel&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Microsoft® .NET remoting provides a framework that allows objects to interact with one another across application domains. The framework provides a number of services, including activation and lifetime support, as well as communication channels responsible for transporting messages to and from remote applications. Formatters are used for encoding and decoding the messages before they are transported by the channel. Applications can use binary encoding where performance is critical, or XML encoding where interoperability with other remoting frameworks is essential. All XML encoding uses the SOAP protocol in transporting messages from one application domain to the other. Remoting was designed with security in mind, and a number of hooks are provided that allow channel sinks to gain access to the messages and serialized stream before the stream is transported over the channel.&lt;br /&gt;&lt;br /&gt;Managing the lifetime of remote objects without support from the underlying framework is often cumbersome. .NET remoting provides a number of activation models to choose from. These models fall into two categories: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Client-activated objects&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Server-activated objects &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Client-activated objects are under the control of a lease-based lifetime manager that ensures that the object is garbage collected when its lease expires. In the case of server-activated objects, developers have a choice of selecting either a "single call" or "singleton" model. The lifetime of singletons are also controlled by lease-based lifetime.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remote Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;One of the main objectives of any remoting framework is to provide the necessary infrastructure that hides the complexities of calling methods on remote objects and returning results. Any object outside the application domain of the caller should be considered remote, even if the objects are executing on the same machine. Inside the application domain, all objects are passed by reference while primitive data types are passed by value. Since local object references are only valid inside the application domain where they are created, they cannot be passed to or returned from remote method calls in that form. All local objects that have to cross the application domain boundary have to be passed by value and should be marked with the &lt;strong&gt;[serializable]&lt;/strong&gt; custom attribute, or they have to implement the &lt;strong&gt;ISerializable&lt;/strong&gt; interface. When the object is passed as a parameter, the framework serializes the object and transports it to the destination application domain, where the object will be reconstructed. Local objects that cannot be serialized cannot be passed to a different application domain and are therefore nonremotable.&lt;br /&gt;&lt;br /&gt;Any object can be changed into a remote object by deriving it from &lt;strong&gt;MarshalByRefObject&lt;/strong&gt;. When a client activates a remote object, it receives a proxy to the remote object. All operations on this proxy are appropriately indirected to enable the remoting infrastructure to intercept and forward the calls appropriately. This indirection does have some impact on performance, but the JIT compiler and execution engine (EE) have been optimized to prevent unnecessary performance penalties when the proxy and remote object reside in the same application domain. In cases where the proxy and remote objects are in different application domains, all method call parameters on the stack are converted into messages and transported to the remote application domain, where the messages are turned back into a stack frame and the method call is invoked. The same procedure is used for returning results from the method call.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Proxy Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Proxy objects are created when a client activates a remote object. The proxy object acts as a representative of the remote object and ensures that all calls made on the proxy are forwarded to the correct remote object instance. In order to understand exactly how proxy objects work, we need to examine them in more detail. When a client activates a remote object, the framework creates a local instance of the class &lt;strong&gt;TransparentProxy&lt;/strong&gt; that contains a list of all classes, as well as interface methods of the remote object. Since the TransparentProxy class is registered with the CLR when it gets created, all method calls on the proxy are intercepted by the runtime. Here the call is examined to determine if it is a valid method of the remote object and if an instance of the remote object resides in the same application domain as the proxy. If this is true, a simple method call is routed to the actual object. If the object is in a different application domain, the call parameters on the stack are packaged into an &lt;strong&gt;IMessage&lt;/strong&gt; object and forwarded to a &lt;strong&gt;RealProxy&lt;/strong&gt; class by calling its &lt;strong&gt;Invoke&lt;/strong&gt; method. This class (or rather an internal implementation of it) is responsible for forwarding messages to the remote object. Both the TransparentProxy and RealProxy classes are created under the covers when a remote object is activated, but only the TransparentProxy is returned to the client. &lt;br /&gt;&lt;br /&gt;In order to gain a better understanding of these proxy objects, we need to take a detour and briefly mention &lt;strong&gt;ObjRef&lt;/strong&gt;. A detailed description of ObjRef is provided in the Activation section. The following scenario describes briefly how ObjRef and the two proxy classes are related. It is important to note that this is a very broad description of the process; some variations exist, depending on whether objects are client or server activated, and if they are singleton or single-call objects. &lt;br /&gt;&lt;br /&gt;A remote object is registered in an application domain on a remote machine. The object is marshaled to produce an ObjRef. The ObjRef contains all the information required to locate and access the remote object from anywhere on the network. This information includes the strong name of the class, the class's hierarchy (its parents), the names of all the interfaces the class implements, the object URI, and details of all available channels that have been registered. The remoting framework uses the object URI to retrieve the ObjRef instance created for the remote object when it receives a request for that object. &lt;br /&gt;&lt;br /&gt;A client activates a remote object by calling new or one of the &lt;strong&gt;Activator&lt;/strong&gt; functions like &lt;strong&gt;CreateInstance&lt;/strong&gt;. In the case of server-activated objects, the TransparentProxy for the remote object is produced in the client application domain and returned to the client, no remote calls are made at all. The remote object is only activated when the client calls a method on the remote object. This scenario will obviously not work for client-activated objects, since the client expects the framework to activate the object when asked to do so. When a client calls one of the activation methods, an activation proxy is created on the client and a remote call is initiated to a remote activator on the server using the URL and object URI as the endpoint. The remote activator activates the object, and an ObjRef is streamed to the client, where it is unmarshaled to produce a TransparentProxy that is returned to the client. &lt;br /&gt;&lt;br /&gt;During unmarshaling, the ObjRef is parsed to extract the method information of the remote object and both the TransparentProxy and RealProxy objects are created. The content of the parsed ObjRef is added to the internal tables of the TransparentProxy before the latter is registered with the CLR. &lt;br /&gt;&lt;br /&gt;The TransparentProxy is an internal class that cannot be replaced or extended. On the other hand, the RealProxy and ObjRef classes are public and can be extended and customized when necessary. The RealProxy class is an ideal candidate for performing load balancing for example, since it handles all function calls on a remote object. When Invoke is called, a class derived from RealProxy can obtain load information about servers on the network and route the call to an appropriate server. Simply request a &lt;strong&gt;MessageSink&lt;/strong&gt; for the required ObjectURI from the Channel and call &lt;strong&gt;SyncProcessMessage&lt;/strong&gt; or &lt;strong&gt;AsyncProcessMessage&lt;/strong&gt; to forward the call to the required remote object. When the call returns, the RealProxy automatically handles the return parameter.&lt;br /&gt;&lt;br /&gt;Here's a code snippet that shows how to use a derived RealProxy class.&lt;br /&gt;&lt;br /&gt;   MyRealProxy proxy = new MyRealProxy(typeof(Foo));&lt;br /&gt;   Foo obj = (Foo)proxy.GetTransparentProxy();&lt;br /&gt;   int result = obj.CallSomeMethod();&lt;br /&gt;&lt;br /&gt;The TransparentProxy obtained above can be forwarded to another application domain. When the second client attempts to call a method on the proxy, the remoting framework will attempt to create an instance of MyRealProxy, and if the assembly is available, all calls will be routed through this instance. If the assembly is not available, calls will be routed through the default remoting RealProxy.&lt;br /&gt;&lt;br /&gt;An ObjRef can easily be customized by providing replacements for default ObjRef properties &lt;strong&gt;TypeInfo&lt;/strong&gt;, &lt;strong&gt;EnvoyInfo&lt;/strong&gt;, and &lt;strong&gt;ChannelInfo&lt;/strong&gt;. The following code shows how this can be done.&lt;br /&gt;&lt;br /&gt;public class ObjRef {&lt;br /&gt;  public virtual IRemotingTypeInfo TypeInfo &lt;br /&gt;  {&lt;br /&gt;    get { return typeInfo;}&lt;br /&gt;    set { typeInfo = value;}&lt;br /&gt;  }&lt;br /&gt;  public virtual IEnvoyInfo EnvoyInfo&lt;br /&gt;  {&lt;br /&gt;    get { return envoyInfo;}&lt;br /&gt;    set { envoyInfo = value;}&lt;br /&gt;  }&lt;br /&gt;  public virtual IChannelInfo ChannelInfo &lt;br /&gt;  {&lt;br /&gt;    get { return channelInfo;}&lt;br /&gt;    set { channelInfo = value;}&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Channels&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Channels are used to transport messages to and from remote objects. When a client calls a method on a remote object, the parameters, as well as other details related to the call, are transported through the channel to the remote object. Any results from the call are returned back to the client in the same way. A client can select any of the channels registered on the "server" to communicate with the remote object, thereby allowing developers the freedom to select the channels that best suit their needs. It is also possible to customize any existing channel or build new ones that use different communication protocols. Channel selection is subject to the following rules: &lt;br /&gt;&lt;br /&gt;At least one channel must be registered with the remoting framework before a remote object can be called. Channels must be registered before objects are registered.&lt;br /&gt; &lt;br /&gt;Channels are registered per application domain. There can be multiple application domains in a single process. When a process dies, all channels that it registers are automatically destroyed. &lt;br /&gt;&lt;br /&gt;It is illegal to register the same channel that listens on the same port more than once. Even though channels are registered per application domain, different application domains on the same machine cannot register the same channel listening on the same port. You can register the same channel listening on two different ports. &lt;br /&gt;&lt;br /&gt;Clients can communicate with a remote object using any registered channel. The remoting framework ensures that the remote object is connected to the right channel when a client attempts to connect to it. The client is responsible for calling RegisterChannel on the ChannelService class before attempting to communicate with a remote object. &lt;br /&gt;&lt;br /&gt;All channels derive from IChannel and implement either IChannelReceiver or IchannelSender, depending on the purpose of the channel. Most channels implement both the receiver and sender interfaces to enable them to communicate in either direction. When a client calls a method on a proxy, the call is intercepted by the remoting framework and changed into a message that is forwarded to the RealProxy class (or rather, an instance of a class that implements RealProxy). The RealProxy forwards the message to the channel sink chain for processing. &lt;br /&gt;&lt;br /&gt;This first sink in the chain is normally a formatter sink that serializes the message into a stream of bytes. The message is then passed from one channel sink to the next until it reaches the transport sink at the end of the chain. The transport sink is responsible for establishing a connection with the transport sink on the server side and sending the byte stream to the server. The transport sink on the server then forwards the byte stream through the sink chain on the server side until it reaches the formatter sink, at which point the message is deserialized from its point of dispatch to the remote object itself.&lt;br /&gt;&lt;br /&gt;One confusing aspect of the remoting framework is the relationship between remote objects and channels. For example, how does a SingleCall remote object manage to listen for clients to connect to if the object is only activated when a call arrives?&lt;br /&gt;&lt;br /&gt;Part of the magic relies on the fact that remote objects share channels. A remote object does not own a channel. Server applications that host remote objects have to register the channels they require as well as the objects they wish to expose with the remoting framework. When a channel is registered, it automatically starts listening for client requests at the specified port. When a remote object is registered, an ObjRef is created for the object and stored in a table. When a request comes in on a channel, the remoting framework examines the message to determine the target object and checks the table of object references to locate the reference in the table. If the object reference is found, the framework target object is retrieved from the table or activated when necessary, and then the framework forwards the call to the object. In the case of synchronous calls, the connection from the client is maintained for the duration of the message call. Since each client connection is handled in its own thread, a single channel can service multiple clients simultaneously.&lt;br /&gt;&lt;br /&gt;Security is an important consideration when building business applications, and developers must be able to add security features like authorization or encryption to remote method calls in order to meet business requirements. To accommodate this need, channels can be customized to provide developers with control over the actual transport mechanism of messages both to and from the remote object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;HTTP Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The HTTP channel transports messages to and from remote objects using the SOAP protocol. All messages are passed through the SOAP formatter, where the message is changed into XML and serialized, and the required SOAP headers are added to the stream. It is also possible to configure the HTTP Channel to use the binary formatter. The resulting data stream is then transported to the target URI using the HTTP protocol.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;TCP Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The TCP channel uses a binary formatter to serialize all messages to a binary stream and transport the stream to the target URI using the TCP protocol. It is also possible to configure the TCP channel to the SOAP formatter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Activation&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The remoting framework supports server and client activation of remote objects. Server activation is normally used when remote objects are not required to maintain any state between method calls. It is also used in cases where multiple clients call methods on the same object instance and the object maintains state between function calls. On the other hand, client-activated objects are instantiated from the client, and the client manages the lifetime of the remote object by using a lease-based system provided for that purpose.&lt;br /&gt;&lt;br /&gt;All remote objects have to be registered with the remoting framework before clients can access them. Object registration is normally done by a hosting application that starts up, registers one or more channels with &lt;strong&gt;ChannelServices&lt;/strong&gt;, registers one or more remote objects with &lt;strong&gt;RemotingConfiguration&lt;/strong&gt;, and then waits until it is terminated. It is important to note that the registered channels and objects are only available while the process that registered them is alive. When the process quits, all channels and objects registered by this process are automatically removed from the remoting services where they were registered. The following four pieces of information are required when registering a remote object with the framework: &lt;br /&gt;&lt;br /&gt;The assembly name in which the class is contained. &lt;br /&gt;&lt;br /&gt;The Type name of the remote object. &lt;br /&gt;&lt;br /&gt;The object URI that clients will use to locate the object. &lt;br /&gt;&lt;br /&gt;The object mode required for server activation. This can be &lt;strong&gt;SingleCall&lt;/strong&gt; or &lt;strong&gt;Singleton&lt;/strong&gt;. &lt;br /&gt;&lt;br /&gt;A remote object can be registered by calling &lt;strong&gt;RegisterWellKnownServiceType&lt;/strong&gt;, passing the information above as parameters, or by storing the above information in a configuration file and then calling Configure, thus passing the name of the configuration file as a parameter. Either of these two functions can be used to register remote objects as they perform exactly the same function. The latter is more convenient to use since the contents of the configuration file can be altered without recompiling the host application. The following code snippet shows how to register the HelloService class as a SingleCall remote object.&lt;br /&gt;&lt;br /&gt;RemotingConfiguration.RegisterWellKnownServiceType(&lt;br /&gt;  Type.GetType("RemotingSamples.HelloServer,object"), &lt;br /&gt;  "SayHello", &lt;br /&gt;  WellKnownObjectMode.SingleCall);&lt;br /&gt;&lt;br /&gt;Where RemotingSamples is the namespace, HelloServer is the name of the class and Object.dll is the name of the assembly. SayHello is the Object URI where our service will be exposed. The Object URI can be any text string for direct hosting, but requires a .rem or .soap extension if the service will be hosted in IIS. It is therefore advisable to these extensions for all remoting endpoints (URI's).&lt;br /&gt;&lt;br /&gt;When the object is registered, the framework creates an object reference for this remote object and then extracts the required metadata about the object from the assembly. This information, together with the URI and assembly name, is then stored in the object reference that is filed in a remoting framework table used for tracking registered remote objects. It is important to note that the remote object itself is not instantiated by the registration process. This only happens when a client attempts to call a method on the object or activates the object from the client side.&lt;br /&gt;&lt;br /&gt;Any client that knows the URI of this object can now obtain a proxy for this object by registering the channel it prefers with ChannelServices and activating the object by calling &lt;strong&gt;new&lt;/strong&gt;, &lt;strong&gt;GetObject&lt;/strong&gt;, or &lt;strong&gt;CreateInstance&lt;/strong&gt;. The following code snippet shows an example of how this is done.&lt;br /&gt;&lt;br /&gt;""      ChannelServices.RegisterChannel(new TcpChannel());&lt;br /&gt;      HelloServer obj =  (HelloServer)Activator.GetObject(&lt;br /&gt;        typeof(RemotingSamples.HelloServer), &lt;br /&gt;        "tcp://localhost:8085/SayHello");&lt;br /&gt;&lt;br /&gt;Here "tcp://localhost:8085/SayHello" specifies that we wish to connect to the remote object at the SayHello endpoint using TCP on port 8085. The compiler obviously requires type information about the HelloServer class when this client code is compiled. This information can be provided in one of the following ways: &lt;br /&gt;&lt;br /&gt;Provide a reference to the assembly where the HelloService class is stored. &lt;br /&gt;&lt;br /&gt;Split the remote object into an implementation and interface class and use the interface as a reference when compiling the client. &lt;br /&gt;&lt;br /&gt;Use the SOAPSUDS tool to extract the required metadata directly from the endpoint. This tool connects to the endpoint provided, extracts the metadata, and generates an assembly or source code that can then be used to compile the client. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;GetObject&lt;/strong&gt; or &lt;strong&gt;new&lt;/strong&gt; can be used for server activation. It is important to note that the remote object is not instantiated when either of these calls is made. As a matter of fact, no network calls are generated at all. The framework obtains enough information from the metadata to create the proxy without connecting to the remote object at all. A network connection is only established when the client calls a method on the proxy. When the call arrives at the server, the framework extracts the URI from the message, examines the remoting framework tables to locate the reference for the object that matches the URI, and then instantiates the object if necessary, forwarding the method call to the object. If the object is registered as SingleCall, it is destroyed after the method call is completed. A new instance of the object is created for each method called. The only difference between GetObject and new is that the former allows you to specify a URL as a parameter, where the latter obtains the URL from the configuration.&lt;br /&gt;&lt;br /&gt;CreateInstance or new can be used for client-activated objects. Both allow instantiating an object using constructors with parameters. An activation request is sent to the server when a client attempts to activate a client-activated object. The lifetime of client-activated objects is controlled by the leasing service provided by the remoting framework. Object leasing is described in the following section.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Object Lifetime with Leasing&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Each application domain contains a lease manager that is responsible for administrating leases in its domain. All leases are examined periodically for expired lease times. If a lease has expired, one or more of the lease's sponsors are invoked where they are given the opportunity to renew the lease. If none of the sponsors decides to renew the lease, the lease manager removes the lease and the object is garbage collected. The lease manager maintains a lease list with leases sorted by remaining lease time. The leases with the shortest remaining time are stored at the top of the list.&lt;br /&gt;&lt;br /&gt;Leases implement the &lt;strong&gt;ILease&lt;/strong&gt; interface and store a collection of properties that determine which policies and methods to renew. Leases can be renewed on call. Each time a method is called on the remote object, the lease time is set to the maximum of the current &lt;strong&gt;LeaseTime&lt;/strong&gt; plus the &lt;strong&gt;RenewOnCallTime&lt;/strong&gt;. When the LeaseTime elapses, the sponsor is asked to renew the lease. Since we have to deal with unreliable networks from time to time, the situation might arise where the lease sponsor is unavailable, and to ensure that we don't leave zombie objects on a server each lease has a SponsorshipTimeout. This value specifies the amount of time to wait for a sponsor to reply before the lease is terminated. If the SponsorshipTimeout is null, the &lt;strong&gt;CurrentLeaseTime&lt;/strong&gt; will be used to determine when the lease should expire. If the CurrentLeaseTime has a value of zero, the lease will not expire. Configuration or APIs can be used to the override the default values for &lt;strong&gt;InitialLeaseTime&lt;/strong&gt;, &lt;strong&gt;SponsorshipTimeout&lt;/strong&gt;, and &lt;strong&gt;RenewOnCallTime&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;The lease manager maintains a list of the sponsors (they implement the &lt;strong&gt;ISponsor&lt;/strong&gt; interface) stored in order of decreasing sponsorship time. When a sponsor is needed for renewing the lease's time, one or more sponsors from the top of the list is asked to renew the time. The top of the list represents the sponsor that previously requested the largest lease renewal time. If a sponsor doesn't respond in the &lt;strong&gt;SponsorshipTimeOut&lt;/strong&gt; time span, it will be removed from the list. An object's lease can be obtained by calling &lt;strong&gt;GetLifetimeService&lt;/strong&gt;, passing the object for which the lease is required as a parameter. This call is a static method of the &lt;strong&gt;RemotingServices&lt;/strong&gt; class. If the object is local to the application domain, the parameter to this call is a local reference to the object, and the lease returned is a local reference to the lease. If the object is remote, the proxy is passed as a parameter, and a transparent proxy for the lease is returned to the caller.&lt;br /&gt;&lt;br /&gt;Objects can provide their own leases and thereby control their own lifetime. They do this by overriding the &lt;strong&gt;InitializeLifetimeService&lt;/strong&gt; method on &lt;strong&gt;MarshalByRefObject&lt;/strong&gt; as follows:&lt;br /&gt;&lt;br /&gt;public class Foo : MarshalByRefObject {&lt;br /&gt;  public override Object InitializeLifetimeService()&lt;br /&gt;  {&lt;br /&gt;    ILease lease = (ILease)base.InitializeLifetimeService();&lt;br /&gt;    if (lease.CurrentState == LeaseState.Initial)  {&lt;br /&gt;      lease.InitialLeaseTime = TimeSpan.FromMinutes(1);&lt;br /&gt;      lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);&lt;br /&gt;      lease.RenewOnCallTime = TimeSpan.FromSeconds(2);&lt;br /&gt;    }&lt;br /&gt;    return lease;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The lease properties can only be changed when a lease is in the initial state. The implementation of InitializeLifetimeService normally calls the corresponding method of the base class to retrieve the existing lease for the remote object. If the object has never been marshaled before, the lease returned will be in its initial state and the lease properties can be set. Once the object has been marshaled, the lease goes from the initial to the active state and any attempt to initialize the lease properties will be ignored (an exception is thrown). InitializeLifetimeService is called when the remote object is activated. A list of sponsors for the lease can be supplied with the activation call and additional sponsors can be added at any time while the lease is active.&lt;br /&gt;&lt;br /&gt;Lease times can be extended as follows: &lt;br /&gt;&lt;br /&gt;A client can invoke the &lt;strong&gt;Renew&lt;/strong&gt; method on the &lt;strong&gt;Lease&lt;/strong&gt; class. &lt;br /&gt;&lt;br /&gt;The lease can request a &lt;strong&gt;Renewal&lt;/strong&gt; from a sponsor.&lt;br /&gt; &lt;br /&gt;When a client invokes a method on the object, the lease is automatically renewed by the &lt;strong&gt;RenewOnCall&lt;/strong&gt; value. &lt;br /&gt;&lt;br /&gt;Once a lease has expired, its internal state changes from Active to Expired, no further calls to the sponsors are made, and the object will be garbage collected. Since it is often difficult for remote objects to perform a callback on a sponsor if the sponsor is deployed on the Web or behind a firewall, the sponsor does not have to be at the same location as the client. It can be on any part of the network that is reachable by the remote object.&lt;br /&gt;&lt;br /&gt;Using leases to manage the lifetime of remote objects is an alternative approach to reference counting, which tends to be complex and inefficient over unreliable network connections. Although one could argue that the lifetime of a remote object is extended longer than required, the reduction in network traffic devoted to reference counting and pinging clients makes leasing a very attractive solution.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Providing a perfect remoting framework that meets the needs of the majority of business applications is certainly a difficult, if not impossible, endeavor. By providing a framework that can be extended and customized as required, Microsoft has taken a key step in the right direction.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Appendix A: Remoting Sample Using a TCP Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This appendix shows how to write a simple "Hello World" remote application. The client passes a String to the remote object that appends the words "Hi There" to the string and returns the result back to the client. In order to modify this sample to use HTTP rather than TCP, simply replace TCP with HTTP in the source files.&lt;br /&gt;&lt;br /&gt;Save this code as &lt;strong&gt;server.cs&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.Remoting;&lt;br /&gt;using System.Runtime.Remoting.Channels;&lt;br /&gt;using System.Runtime.Remoting.Channels.Tcp;&lt;br /&gt;namespace RemotingSamples {&lt;br /&gt;  public class Sample {&lt;br /&gt;    public static int Main(string [] args) {&lt;br /&gt;      TcpChannel chan = new TcpChannel(8085);&lt;br /&gt;      ChannelServices.RegisterChannel(chan);&lt;br /&gt;      RemotingConfiguration.RegisterWellKnownServiceType&lt;br /&gt;      (Type.GetType("RemotingSamples.HelloServer,object"), &lt;br /&gt;      "SayHello", WellKnownObjectMode.SingleCall);&lt;br /&gt;      System.Console.WriteLine("Hit &lt;enter&gt; to exit...");&lt;br /&gt;      System.Console.ReadLine();&lt;br /&gt;      return 0;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Save this code as &lt;strong&gt;client.cs&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.Remoting;&lt;br /&gt;using System.Runtime.Remoting.Channels;&lt;br /&gt;using System.Runtime.Remoting.Channels.Tcp;&lt;br /&gt;namespace RemotingSamples {&lt;br /&gt;  public class Client&lt;br /&gt;  {&lt;br /&gt;    public static int Main(string [] args)&lt;br /&gt;    {&lt;br /&gt;      TcpChannel chan = new TcpChannel();&lt;br /&gt;      ChannelServices.RegisterChannel(chan);&lt;br /&gt;      HelloServer obj = &lt;br /&gt;   (HelloServer)Activator.GetObject(typeof(RemotingSamples.HelloServer)&lt;br /&gt;   , "tcp://localhost:8085/SayHello");&lt;br /&gt;      if (obj == null) &lt;br /&gt;      System.Console.WriteLine("Could not locate server");&lt;br /&gt;      else Console.WriteLine(obj.HelloMethod("Caveman"));&lt;br /&gt;      return 0;&lt;br /&gt;    } &lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Save this code as &lt;strong&gt;object.cs&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.Remoting;&lt;br /&gt;using System.Runtime.Remoting.Channels;&lt;br /&gt;using System.Runtime.Remoting.Channels.Tcp;&lt;br /&gt;namespace RemotingSamples {&lt;br /&gt;  public class HelloServer : MarshalByRefObject {&lt;br /&gt;    public HelloServer() {&lt;br /&gt;      Console.WriteLine("HelloServer activated");&lt;br /&gt;    }&lt;br /&gt;    public String HelloMethod(String name) {&lt;br /&gt;      Console.WriteLine("Hello.HelloMethod : {0}", name);&lt;br /&gt;      return "Hi there " + name;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here's the makefile:&lt;br /&gt;&lt;br /&gt;all: object.dll server.exe client.exe&lt;br /&gt;&lt;br /&gt;object.dll: share.cs&lt;br /&gt;   csc /debug+ /target:library /out:object.dll object.cs&lt;br /&gt;&lt;br /&gt;server.exe: server.cs&lt;br /&gt;   csc /debug+ /r:object.dll /r:System.Runtime.Remoting.dll server.cs&lt;br /&gt;&lt;br /&gt;client.exe: client.cs server.exe&lt;br /&gt;   csc /debug+ /r:object.dll /r:server.exe &lt;br /&gt;   /r:System.Runtime.Remoting.dll client.cs&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is .NET Remoting? &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;.NET Remoting is an enabler for application communication. It is a generic system for different applications to use to communicate with one another. .NET objects are exposed to remote processes, thus allowing interprocess communication. The applications can be located on the same computer, different computers on the same network, or even computers across separate networks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Remoting versus Distributed COM&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In the past interprocess communication between applications was handled through Distributed COM, or DCOM. DCOM works well and the performance is adequate when applications exist on computers of similar type on the same network. However, DCOM has its drawbacks in the Internet connected world. DCOM relies on a proprietary binary protocol that not all object models support, which hinders interoperability across platforms. In addition, have you tried to get DCOM to work through a firewall? DCOM wants to communicate over a range of ports that are typically blocked by firewalls. There are a ways to get it to work, but they either decrease the effectiveness of the firewall (why bother to even have the firewall if you open up a ton of ports on it), or require you to get a firewall that allows support for binary traffic over port 80.&lt;br /&gt;&lt;br /&gt;.NET Remoting eliminates the difficulties of DCOM by supporting different transport protocol formats and communication protocols. This allows .NET Remoting to be adaptable to the network environment in which it is being used. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET Remoting versus Web Services&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Unless you have been living in a cave, or are way behind in your reading, you have probably read something about Web services. When you read the description of .NET Remoting it may remind you a lot of what you're read about Web services. That is because Web services fall under the umbrella of .NET Remoting, but have a simplified programming model and are intended for a wide target audience. &lt;br /&gt;&lt;br /&gt;Web services involve allowing applications to exchange messages in a way that is platform, object model, and programming language independent. Web services are stateless and know nothing about the client that is making the request. The clients communicate by transferring messages back and forth in a specific format known as the Simple Object Access Protocol, or SOAP. (Want to get some funny looks in the hallway? Stand around in the hallway near the marketing department with your colleagues and discuss the benefits of using SOAP). &lt;br /&gt;&lt;br /&gt;The following list outlines some of the major differences between .NET Remoting and Web services that will help you to decide when to use one or the other: &lt;br /&gt;&lt;br /&gt;ASP.NET based Web services can only be accessed over HTTP. .NET Remoting can be used across any protocol.&lt;br /&gt;&lt;br /&gt;Web services work in a stateless environment where each request results in a new object created to service the request. .NET Remoting supports state management options and can correlate multiple calls from the same client and support callbacks.&lt;br /&gt;&lt;br /&gt;Web services serialize objects through XML contained in the SOAP messages and can thus only handle items that can be fully expressed in XML. .NET Remoting relies on the existence of the common language runtime assemblies that contain information about data types. This limits the information that must be passed about an object and allows objects to be passed by value or by reference.&lt;br /&gt;&lt;br /&gt;Web services support interoperability across platforms and are good for heterogeneous environments. .NET Remoting requires the clients be built using .NET, or another framework that supports .NET Remoting, which means a homogeneous environment. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Application Domain&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Application Domain is a Sub Process. Traditionally Process was compartmentalized to Threads. With .NET Remoting Process is compartmentalized to Application Domains (that run as Threads). An Application running in one Application Domain would access another Application Domain in the same Process, machine or another Machine through Remoting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Platform Independence&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When a technology is not tied to a specific domain , it is said to be Platform Independent. The advantage of Web Services (when compared to Remoting) is Platform Independence. Remoting is Plafform dependent.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Loose Coupling&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When it is easier to handle versioning issues between the Client and Server, it is termed Loose Coupling.&lt;br /&gt;&lt;br /&gt;XML Web Services have the advantage Loose Coupling.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Tight Coupling&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When versioning issues are difficult to handle, it is termed Tight Coupling.&lt;br /&gt;&lt;br /&gt;.NET Remoting has the advantage of Tight Coupling.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Interoperability&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When different Platforms can work together it is termed Interoperability.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SOAP&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Simple Object Access Protocol. It is used in invoking object across Application domains and serves as an alternative to Binary format. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SOAP Document Style&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SOAP Document Style is currently not supported by .NET Remoting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Payload Encoding&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The method of Encoding applied while passing parameters to a remote method is known as Payload Encoding. .NET Remoting supports SOAP and Binary Encoding Mechanisms.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The medium of exchange through which a client and sever can interact is known as Channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;HttpChannel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This channel is used in Internet Scenarios.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Proxy&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Proxy is a representative of a remote object. The client invoked methods on a proxy that in turn invokes the remote object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Transparent Proxy&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The proxy itself is split into Transparent Proxy and Real Proxy. Client invokes the method in Transparent Proxy. The Transparent proxy invokes the method Invoke() in the Real proxy.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Real Proxy&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Invoke() method in Real Proxy uses the message sink  to pass the message to the channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MarshalByRefObject&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object that must be invoked across the application domain boundary must inherit MarshalByRefObject. This enables the object to be marshalled when it moves across the boundary.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Custom Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;New channels can be defined by a Programmer that would enable more functionality to be integrated into Remoting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Messages&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Messages are sent into a channel. The Client and Server interact through Messages.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Formatter&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Formatter defines how messages are transferred into the channel. There are two types of Formatters: SOAP Formatter and Binary Formatter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Custom Formatters&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Programmer can create user defined formatters and they are known as Custom Formatters.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SOAP Formatter&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This kind of Formater can be used to comminicate with a Web Service that is not based on the .NET Framework.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Binary Formatter&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Binary formatters are fast and can be used efficiently in an intranet environment.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Interceptor&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An interceptor can modify the messages before it goes outside the door into the channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Message Sink&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It is an Interceptor that stands between the Real Proxy and the channel. The sink can perform some interception before the message moves to the channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Envoy Sink&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Envoy Sink is created from the Server Context.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Server Context Sink&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Once the message is received on the server side of the channel, it is passed to the Server Context Sink.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Object Context Sink&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object context sink is associated with an object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Activator&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An Activator creates a Proxy for a Remote object&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Server Activated Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;For a Server Activated Object, the object does not hold state. The object dies once the Invoke ends.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Client Activated Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Client Activated Object holds State. The object would exist until the leasetime expires.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Configuration File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Configuration files are an alternative to define the settings programmatically. Configuration files are especially useful when you do remoting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Custom Proxy&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Custom Proxy is programmer defined Real Proxy. You can replace a Real Proxy with a Custom Proxy.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Tcp Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This channel is used in intranet environment.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Ipc Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This channel is used when the remoting object exists locally.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Pluggable&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object is said to be Pluggable when it can be replaced with a similar(often custom)  object. .NET Remoting offers several opportunities for implementing Pluggability.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Context is a boundary containing a collection of objects.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Sub Process&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Sub Process is a term that is sometimes used to describe an Application Boundary.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Context Bound Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Context Bound Object derives from a MarshalByRef Object and is bound to a context. Outside the context a proxy is needed to access the object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Context Attributes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Context is always created in accordance to the specifications described by Context Attributes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default Context&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A context is created when an application domain is created and this context is known as Default Context.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Context Properties&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Context Attributes are defined by Context Properties.&lt;br /&gt;.&lt;br /&gt;&lt;strong&gt;Distributed Identity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Remote object is said to have Distributed Identity.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Lifetime Services&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The lifetime of an object that resides in a server is determined by Lifetime Services.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Leasing Features&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object could be assigned lifetime and this is known as leasing.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Port&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Channel is a logical component that is often associated with a Physical Port.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Multiple Channels&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Server can listen to Multiple Channels&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Client Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Both the Server and client must create a channel. The channel on the client side is known as Client Channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Server Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The channel on the server side is known as Server Channel.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Well Known Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Server Activated Object is also known as Well Known Object&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Uniform Resource Identifier&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A URI is used to indicate the Network Location of a Remote object, which is different from the name or type of the object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SingleCall&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Server activated object could be created in either single call or singleton miode. A Singecall object is created new for a call and is destroyed immediately after the call (thereby does not hold state)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Singleton&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Singleton object is used when there is a need to share data across clients. A Singleton object holds state.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Marshal By Value&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object is said to be marshaled by value when instead of using a proxy, the object itself is transmitted to the client. Thereby the object in the client is independent of the object in the server (or the other way around). Such an object does not have a remote identity.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Serializable&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object that can be marshalled by value is known as a Serializable object. An object can be made serializable by including the attribute Serializable to it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Marshall By Reference&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object marshalled by reference is accessed through a proxy and thereby has a remote identity.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Non remotable object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An object that can be marshalled neither by value nor by reference is known as non remotable object&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Deserialization Level&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Serialization and Deserialization phases can be easily used by hackers to harm an application. To overcome this problem Deserialization levels are introduced. There are two deserialization levels: Low and Full. With low deserialization level it is not possible to pass ObjRef objects and objects that implement Isponsor interface as parameters. With full deserialization level you can pass any object as parameter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Directional Attributes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;These are similar to the in, out, inout parameters used in RDBMS like Oracle and SQL Server. Directional attributes could be used when parameters are passed to a remote method.&lt;br /&gt;&lt;br /&gt;Traditionally COM implemeted the following Directional attributes.&lt;br /&gt;&lt;br /&gt;[in]&lt;br /&gt;[out]&lt;br /&gt;[in, out]&lt;br /&gt;&lt;br /&gt;C# implements the same in the following manner:&lt;br /&gt;&lt;br /&gt;ref  - The argument is marshalled in both directions&lt;br /&gt;out  - The data is sent from the server to the client&lt;br /&gt;(no parameter) – The data is sent from the client to the server.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Leasing Distributed Garbage Collector&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is the solution provided by .NET for Lifetime Management of Client Activated Objects and Well known singleton objects.&lt;br /&gt;&lt;br /&gt;Once a lease expires, the remote object is disconnected and garbage collected.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Lease Time&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Lease Time defines the lifetime of an object. When lease time reaches zero, the object is disconnected and garbage collected.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Lease Renewal&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The lease time could be extended when necessary and this is known as Lease Renewal.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Implicit Renewal&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Whenever an object is called, its lease time is renewed (to the value specified by RenewOnCallTime)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explicit Renewal&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The lease time is explicitly renewed by the client&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Sponsoring Renewal&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Sponsor defines a Lease Extension Time, when the lease expires, the sponsor is asked for a renewal.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Predefined Channel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Channels can be defined programmtically in .NET 2.0. Prior to .NET 2.0 Predefined channels are defined in machine.config configuration file. In .NET 2.0 Predefined channels can be defined by the RemotingConfiguration class for better performance.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Delayed Loading&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The client need not define a channel and a channel in the machine.config is automatically used provided the channel entry in the file hs delayLoadAsClientChannel set to true.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Interfaces&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Separation of client and server code is achieved using interfaces.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Soapsuds&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Instead of intefaces, soapsuds can also be used for a HTTP channel with SOAP formatter. Soapsuds generate a proxy (an assembly) and this Proxy could be used instead of an interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Asynchronous Remoting&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In Synchronous Remoting, the client waits until the remote object invocation ends. In Asynchronous remoting the client does not wait. This is achieved using Delegates.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Impersonation&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If Impersonation is permitted, the Server can impersonate the user of the client, to access resources under its name.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Call Context&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;State can be maintained in the client isntead of server and this is achieved using Call Context. A Call context is implicitly passed along with the parameters to the remote method, for every call.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-8020486561213554168?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/8020486561213554168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=8020486561213554168' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/8020486561213554168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/8020486561213554168'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-remoting.html' title='.NET Remoting'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-1608149668335758252</id><published>2008-06-09T04:00:00.000-07:00</published><updated>2008-12-09T16:00:18.492-08:00</updated><title type='text'>.NET Reflection</title><content type='html'>&lt;strong&gt;Working with Reflection in VB.NET&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Reflection is a very nice feature introduced in the Microsoft .NET Framework. When you compile your program code for the .NET Framework to execute it is compiled into the MSIL (Microsoft Intermediate Language) codes and this code is placed in files called assemblies. Unlike DLL’s, the previous containers for compiled codes, assemblies are self explaining. This means they can describe their content unlike COM DLL’s which need a type library and need to store their information in the system’s registry.&lt;br /&gt;&lt;br /&gt;Now &lt;strong&gt;reflection is the capability to get information from assemblies about the contained types, their members, their accessibility, attributes and so more&lt;/strong&gt;. You can programmatically access the properties of any assembly or the currently executing assembly or any type using reflection.&lt;br /&gt;&lt;br /&gt;The Reflection related classes are contained in a namespace called System.Reflection and the main class that is used is Type. To load an external assembly you need to get the reference to that assembly using Assembly class’s Load or LoadFrom method. Then to get all the types present, you can call the GetType or GetTypes method.&lt;br /&gt;In the sample application  attaching below has a test class with some public and private members and used reflection on this to get information about this class. Get the reference to the Type object of this class using the GetType method which returns a reference to the Type of the class. Then enumerate on the Methods present in this class and displayed them in a ListView control.&lt;br /&gt;&lt;br /&gt;You can change and experiment with the code to see how it works. The forcoming content reflects  the information about the Methods of this type you can also get information about the Type itself, weather it is public, is this class sealed and so. Try to go through the .NET Framework SDK and you’ll see a lot of useful members of the Type class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;br /&gt;Without adding reference using classLibrary methods at runtime is done through Reflection. In Refelection we have to use an Activator class. An Activator class is a class, which creates the instance of class method at runtime.&lt;br /&gt;&lt;br /&gt;The generic terms of Reflection are:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Assembly:&lt;/strong&gt; Which hold the dll of classLibrary. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Type:&lt;/strong&gt; Hold the class of classLibrary. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MethodInfo:&lt;/strong&gt; Hold the method of class. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Parameterinfo:&lt;/strong&gt; Keep the parameter information of Method.&lt;br /&gt;&lt;br /&gt;Here there is a class Library, in this class library there are  two classes and some methods in these classes. After making this, build this class Library. On building the class Library a dll will genarate.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reflection Class Library&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Collections.Generic&lt;br /&gt;Imports System.Text&lt;br /&gt;Imports System.Windows.Forms&lt;br /&gt;Namespace reflectionclass&lt;br /&gt;Public Class xx&lt;br /&gt;Public Function sum(ByVal a As Integer, ByVal b As Integer) As Integer&lt;br /&gt;Return a + b&lt;br /&gt;End Function&lt;br /&gt;Public Function [sub](ByVal a As Integer, ByVal b As Integer) As Integer&lt;br /&gt;Return a - b&lt;br /&gt;End Function&lt;br /&gt;End Class&lt;br /&gt;Public Class yy&lt;br /&gt;Public Function mul(ByVal a As Integer, ByVal b As Integer) As Integer&lt;br /&gt;Return a * b&lt;br /&gt;End Function&lt;br /&gt;End Class&lt;br /&gt;End Namespace&lt;br /&gt;After building the calssLibrary we have to make the application. Here in application we are using two ListBox, two buttons, and three textBox. Firstly add the reference of System.Reflection in the application. On clicking of class Button all classes of classLibray will come in listbox1. Here we select the class of which methods we have to use in our application. The application is:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reflection Application:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Imports System&lt;br /&gt;Imports System.Collections.Generic&lt;br /&gt;Imports System.ComponentModel&lt;br /&gt;Imports System.Data&lt;br /&gt;Imports System.Drawing&lt;br /&gt;Imports System.Text&lt;br /&gt;Imports System.Windows.Forms&lt;br /&gt;Imports System.Reflection&lt;br /&gt;Namespace reflectionclient&lt;br /&gt;Partial Public Class Form1&lt;br /&gt;Inherits Form&lt;br /&gt;Public Sub New()&lt;br /&gt;InitializeComponent()&lt;br /&gt;End Sub&lt;br /&gt;Private asm As System.Reflection.Assembly&lt;br /&gt;Private t As Type()&lt;br /&gt;Private ty As Type&lt;br /&gt;Private m As MethodInfo()&lt;br /&gt;Private mm As MethodInfo&lt;br /&gt;Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;'Here wec have to load the assembly of classlibrary by givig the full path of our classLibrary.dll&lt;br /&gt;asm = System.Reflection.Assembly.LoadFrom("C:\Documents and Settings\Administrator\My Documents\Rahul\Reflection\reflectionclass\reflectionclass\bin\Debug\reflectionclass.dll")&lt;br /&gt;End Sub&lt;br /&gt;Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;t = asm.GetTypes()&lt;br /&gt;For i As Integer = 0 To t.Length - 1&lt;br /&gt;listBox1.Items.Add(t(i).FullName)&lt;br /&gt;Next i&lt;br /&gt;End Sub&lt;br /&gt;Private Sub listBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;listBox2.Items.Clear()&lt;br /&gt;ty = asm.GetType(listBox1.SelectedItem.ToString())&lt;br /&gt;m = ty.GetMethods()&lt;br /&gt;For j As Integer = 0 To m.Length - 1&lt;br /&gt;listBox2.Items.Add(m(j).Name)&lt;br /&gt;Next j&lt;br /&gt;End Sub&lt;br /&gt;Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)&lt;br /&gt;mm = ty.GetMethod(listBox2.SelectedItem.ToString())&lt;br /&gt;Dim o As Object&lt;br /&gt;o = Activator.CreateInstance(ty)&lt;br /&gt;Dim oo As Object() = {Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)}&lt;br /&gt;'If there is no parameter in method then on the place of oo pass the null&lt;br /&gt;textBox3.Text = mm.Invoke(o, oo).ToString()&lt;br /&gt;End Sub&lt;br /&gt;End Class&lt;br /&gt;End Namespace&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE0OvpdK23I/AAAAAAAAAFE/DpwAYfweIM8/s1600-h/image1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE0OvpdK23I/AAAAAAAAAFE/DpwAYfweIM8/s320/image1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5209836555682372466" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 1. &lt;br /&gt;&lt;br /&gt;When I click on class Button then all classes of that class library will come in list Box, which .dll I load in assembly.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_xmdzLHNex7Q/SE0OwPxC2SI/AAAAAAAAAFM/YXDbrQ54ixE/s1600-h/image2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_xmdzLHNex7Q/SE0OwPxC2SI/AAAAAAAAAFM/YXDbrQ54ixE/s320/image2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5209836565966280994" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 2: When click on class Button.&lt;br /&gt;&lt;br /&gt;After clicking on class button we saw here in list box there are two classes are coming. If we select here any class then all methods of that class comes in second listbox.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_xmdzLHNex7Q/SE0OwUCZc5I/AAAAAAAAAFU/cBXMM8xyi8o/s1600-h/image3.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_xmdzLHNex7Q/SE0OwUCZc5I/AAAAAAAAAFU/cBXMM8xyi8o/s320/image3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5209836567112807314" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 3: When select any class.&lt;br /&gt;&lt;br /&gt;Here if I select any method and click on Method button then the result of method according to call will become in TextBox.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE0Owu8yZGI/AAAAAAAAAFc/kBlFIwQ00Y0/s1600-h/image4.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SE0Owu8yZGI/AAAAAAAAAFc/kBlFIwQ00Y0/s320/image4.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5209836574337033314" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Figure 4: When select sum method and click on Method Button after entering the value in textBox1 and textBox2.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-1608149668335758252?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/1608149668335758252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=1608149668335758252' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/1608149668335758252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/1608149668335758252'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-reflection.html' title='.NET Reflection'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_xmdzLHNex7Q/SE0OvpdK23I/AAAAAAAAAFE/DpwAYfweIM8/s72-c/image1.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-7453322519287222754</id><published>2008-06-09T01:56:00.000-07:00</published><updated>2008-06-09T02:05:44.691-07:00</updated><title type='text'>.NET Serialization</title><content type='html'>&lt;strong&gt;What Is Serialization?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Serialization is the process of converting an object to a form that can be readily transported. Generally, this means saving the object's data in a way that makes it easy to recreate the object later, through a process called deserialization. Serialization does not save any of the methods of an object—it is assumed that the object's code will be available during the deserialization process, and that the data unique to the object is all that is necessary to recreate the object. The serialized data can take many formats, but they all have one thing in common: the serialized data is not tied to the originating object or system, and the data contains all the information necessary to recreate an object that's identical to the original.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Different Types of Serialization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Microsoft .NET Framework provides an almost bewildering variety of ways to serialize an object. This chapter focuses on XML serialization, but before we get into the details, I'd like to briefly examine and compare the various serialization methods offered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Serialization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;XML serialization allows the public properties and fields of an object to be reduced to an XML document that describes the publicly visible state of the object. This method serializes only public properties and fields—private data will not be persisted, so XML serialization does not provide full fidelity with the original object in all cases. However, because the persistence format is XML, the data being saved can be read and manipulated in a variety of ways and on multiple platforms.&lt;br /&gt;The benefits of XML serialization include the following:&lt;br /&gt;&lt;br /&gt;Allows for complete and flexible control over the format and schema of the XML produced by serialization.&lt;br /&gt;&lt;br /&gt;Serialized format is both human-readable and machine-readable.&lt;br /&gt;&lt;br /&gt;Easy to implement. Does not require any custom serialization-related code in the object to be serialized.&lt;br /&gt;&lt;br /&gt;The XML Schema Definition tool (xsd.exe) can generate an XSD Schema from a set of serializable classes, and generate a set of serializable classes from an XSD Schema, making it easy to programmatically consume and manipulate nearly any XML data in an object-oriented (rather than XML-oriented) fashion.&lt;br /&gt;&lt;br /&gt;Objects to be serialized do not need to be explicitly configured for serialization, either by the SerializableAttribute or by implementing the ISerializable interface.&lt;br /&gt;&lt;br /&gt;The restrictions of XML serialization include the following:&lt;br /&gt;&lt;br /&gt;The class to be serialized must have a default (parameterless) public constructor.&lt;br /&gt;&lt;br /&gt;Read-only properties are not persisted.&lt;br /&gt;&lt;br /&gt;Only public properties and fields can be serialized.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SOAP Serialization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SOAP serialization is similar to XML serialization in that the objects being serialized are persisted as XML. The similarity, however, ends there. The classes used for SOAP serialization reside in the System.Runtime.Serialization namespace rather than the System.Xml.Serialization namespace used by XML serialization. The run-time serialization classes (which include both the SoapFormatter and the BinaryFormatter classes) use a completely different mechanism for serialization than the XmlSerializer class.&lt;br /&gt;&lt;br /&gt;The benefits of SOAP serialization include the following:&lt;br /&gt;&lt;br /&gt;Produces a fully SOAP-compliant envelope that can be processed by any system or service that understands SOAP.&lt;br /&gt;&lt;br /&gt;Supports either objects that implement the ISerializable interface to control their own serialization, or objects that are marked with the SerializableAttribute attribute.&lt;br /&gt;&lt;br /&gt;Can deserialize a SOAP envelope into a compatible set of objects.&lt;br /&gt;&lt;br /&gt;Can serialize and restore non-public and public members of an object.&lt;br /&gt;&lt;br /&gt;The restrictions of SOAP serialization include the following:&lt;br /&gt;&lt;br /&gt;The class to be serialized must either be marked with the SerializableAttribute attribute, or must implement the ISerializable interface and control its own serialization and deserialization.&lt;br /&gt;&lt;br /&gt;Only understands SOAP. It cannot work with arbitrary XML schemas.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Binary Serialization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Binary serialization allows the serialization of an object into a binary stream, and restoration from a binary stream into an object. This method can be faster than XML serialization, and the binary representation is usually much more compact than an XML representation. However, this performance comes at the cost of cross-platform compatibility and human readability.&lt;br /&gt;&lt;br /&gt;The benefits of binary serialization include the following:&lt;br /&gt;&lt;br /&gt;It's the fastest serialization method because it does not have the overhead of generating an XML document during the serialization process.&lt;br /&gt;&lt;br /&gt;The resulting binary data is more compact than an XML string, so it takes up less storage space and can be transmitted quickly.&lt;br /&gt;&lt;br /&gt;Supports either objects that implement the ISerializable interface to control its own serialization, or objects that are marked with the SerializableAttribute attribute.&lt;br /&gt;&lt;br /&gt;Can serialize and restore non-public and public members of an object.&lt;br /&gt;&lt;br /&gt;The restrictions of binary serialization include the following:&lt;br /&gt;&lt;br /&gt;The class to be serialized must either be marked with the SerializableAttribute attribute, or must implement the ISerializable interface and control its own serialization and deserialization.&lt;br /&gt;&lt;br /&gt;The binary format produced is specific to the .NET Framework and it cannot be easily used from other systems or platforms.&lt;br /&gt;&lt;br /&gt;The binary format is not human-readable, which makes it more difficult to work with if the original program that produced the data is not available.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Other Forms of Serialization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A number of other forms of serialization are available in the .NET Framework that are either not intended to be used directly or are specific to a problem domain, which is outside the scope of this book. These other serialization methods include the LosFormatter, which is used to serialize and deserialize page view state in ASP.NET, the CodeDomSerializer, which is used to serialize an object graph representing dynamically generated source code, the binary serialization used in .NET Remoting, and others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-7453322519287222754?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/7453322519287222754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=7453322519287222754' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/7453322519287222754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/7453322519287222754'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-serialization.html' title='.NET Serialization'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-2889174493203458053</id><published>2008-06-04T23:30:00.000-07:00</published><updated>2008-06-04T23:36:14.970-07:00</updated><title type='text'>.NET Utilities</title><content type='html'>&lt;strong&gt;.NET Utilities&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;FileHelpers&lt;/strong&gt;&lt;br /&gt;The FileHelpers are an easy to use library to import/export data from fixed length or delimited records in files, strings or streams.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Automatic C# Code Generator&lt;/strong&gt;&lt;br /&gt;ADCG (Automatic Data Class Generator) is a tool written to speed-up the writing of C# XML class structures.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Resx Editor&lt;/strong&gt;&lt;br /&gt;Resx Editor is a small translation-oriented file editor.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;IP2Location Geolocation .NET Component&lt;/strong&gt;&lt;br /&gt;IP2Location .NET Component is fully managed code written for .NET Framework. The component enables you to discover in real-time, where your web visitors are coming from by IP address. You can then dynamically tailor the content of your site based on your visitors country, region, city, latitude, longitude, ZIP code, ISP and domain name. This component is using a fast and self-contained lookup engine. Therefore, no remote query or database connection required.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;C#Studio&lt;/strong&gt;&lt;br /&gt;C#Studio is an Integrated Development Environment for the creation of C# based .NET applications. This product has been designed to offer an efficient and functional environment that is a joy for the hobbyist, novice or more experienced developer to use.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;ANTER&lt;/strong&gt;&lt;br /&gt;Another Tool for Language Recognition, (formerly PCCTS) is a language tool that provides a framework for constructing recognizers, compilers, and translators from grammatical descriptions containing C++, C# or Java actions.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Grammatica&lt;/strong&gt;&lt;br /&gt;Grammatica is a parser generator for C# and Java. Readable and commented source code for an LL(k) parser can be created, but Grammatica also supports run-time parser creation without ever generating source code.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;FxCop version 1.072&lt;/strong&gt;&lt;br /&gt;FxCop is a code analysis tool that checks your .NET assemblies for conformance to the .NET Framework Design Guidelines.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;FindTypeEx&lt;/strong&gt;&lt;br /&gt;This is a modified version of the FindType sample that comes in the .NET SDK. This modification adds the ability to find all the types which derive (either directly or indirectly) from a specific base.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;NUnit&lt;/strong&gt;&lt;br /&gt;A simple testing framework for .Net languages. Implemented in C#, applies to all .Net languages. Comes with a text mode for inclusion in automated builds, plus a GUI browser. Open Source.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Compiler Tools&lt;/strong&gt;&lt;br /&gt;These are compiler writing tools in the tradition of lex and yacc, but using C# as an implementation language. The tools are written using object-oriented techniques that are natural to C# and are provided in source form to assist an understanding of the standard algorithms used. ....     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Resourcer for .NET&lt;/strong&gt;&lt;br /&gt;Resourcer is an editor for .resources binaries and .resX XML file formats used with the Microsoft.NET platform. The program is written in C# and allows the integration of bitmaps, icons and text strings into resource packages..     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;DatePicker for .NET&lt;/strong&gt;&lt;br /&gt;The DatePicker presented here is a .NET rewrite of the oulook control. It is a ComboBox-like control which shows a Calendar when dropped down.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;WithClass 2000&lt;/strong&gt;&lt;br /&gt;UML Tool now has support for C#. It can reverse engineer C# into class diagrams and generate C# code. Reports for diagrams can be generated in Word, Excel and HTML. A free trial version is available at http://www.microgold.com     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;SharpDevelop&lt;/strong&gt;&lt;br /&gt;SharpDevelop is a free editor for C# (C Sharp) projects on Microsoft's .NET platform. It is open-source (GPL), and you can download both sourcecode and executables from this site. In addition, you can find the latest information and changes on SharpDevelop, as well as get in touch with its author, Mike Krüger.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;NZipLib - A Compression Utility in C# &lt;/strong&gt;&lt;br /&gt;NZipLib is a by-product to our open source IDE SharpDevelop. It is free, C# source code included!     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Reflector for .NET&lt;/strong&gt;&lt;br /&gt;Reflector is a class browser for .NET components (assemblies). It features with a hierarchical assembly view, type and member search index, type reference search, custom attributes view, IL disassembler and an MSDN-like viewer for XML documentations. Assembly dependency trees, supertype/subtype hierarchies and resources can be inspected as well. Function prototypes are displayed in C# and VB syntax. Windows XP enabled. In short: the swiss army knife for .NET programmers.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;QuickModeler&lt;/strong&gt;&lt;br /&gt;QuickModeler is an Add-In for Visual Studio .NET which provides reverse engineering and easy UML modeling functionality to the development environment. It comprises features like autolayout, inheritance and association modeling, cross language modeling, grid, clipboard, etc. It uses the VS.NET extensibility model and comes as a Microsoft Installer Package.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Assembly Explorer&lt;/strong&gt;&lt;br /&gt;In our project we developed a bunch of utility classes. For each one of them we had to create some kind of test application just to enter parameters and display result of method invoked. At some point I decided that WinForm we just created should be the last one. Why could not we create entry form on the fly for each method in utility class, we want to test? With this thought in mind, I dig out mine old little utility that uses reflection to display assembly hierarchy, and make couple of additions.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;.NET Flat Control Library&lt;/strong&gt;&lt;br /&gt;The attached source code contains a library of basic flat controls. Controls are .NET based and can be used only in .NET supported programming languages (C#, VB .NET, J# etc.)     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Code Analyzer Tool&lt;/strong&gt;&lt;br /&gt;Code Analyzer tool enables programmers and QA managers to check C# source for compliance with coding standards and best practices. Code analyzer enables to define your own "policy", which consists of set of rules that define how the code should look like.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Compiler Design in C#&lt;/strong&gt;&lt;br /&gt;In this section I'll share my experience with compiler design using C#. For now there isn't much, but hopefully someone will find this information useful.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;vsPropertyGenerator&lt;/strong&gt;&lt;br /&gt;is an Add-On to Visual Studio .NET for easily creating/removing properties to C# classes. It works like "Generate Getters/Setters" feature from Eclipse IDE.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;TraceView&lt;/strong&gt;&lt;br /&gt;TraceView is a debug utility that captures debug messages from shared memory DBWIN_BUFFER. It provides features such as trace selected processes, apply custom filters at runtime, level of tracing, log messages to log files, and persistent user settings.     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;TDO&lt;/strong&gt;&lt;br /&gt;The attached source code is a too called TDO (Typed Data Object). TDO is a C# source code generator which works on both versions Microsoft Framework .NET 1.0 and 1.1. This tool generates source code to work with databases including SQL Server 7 and SQL Server 2000.&lt;br /&gt;     &lt;br /&gt;&lt;strong&gt;Prof-It: A C# Profiler&lt;/strong&gt;&lt;br /&gt;Prof-It is an easy-to-use standalone profiler for C# that measures execution frequencies for each statement while keeping the instrumentation of the source code to a minimum. An optimized strategy for finding basic blocks, incrementing their counters and calculating counters from others makes Prof-It faster than every other profiler, that can collect execution frequencies for each line of code!     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;FxCop&lt;/strong&gt;&lt;br /&gt;FxCop analyzes programming elements in managed assemblies, called targets, and provides an informational report containing messages about the targets, including suggestions on how to improve the source code used to generate them.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-2889174493203458053?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/2889174493203458053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=2889174493203458053' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/2889174493203458053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/2889174493203458053'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-utilities.html' title='.NET Utilities'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-1801766651880996445</id><published>2008-06-04T02:22:00.000-07:00</published><updated>2008-06-04T02:27:06.230-07:00</updated><title type='text'>.NET Tools</title><content type='html'>&lt;strong&gt;.NET Tools&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ASP.NET IIS Registration Tool (Aspnet regiis.exe) &lt;/strong&gt;&lt;br /&gt;This tool is to facilitate the administrator or the installation program to update the script maps for ASP.NET application. This helps point the ASP.NET ISAPI version associated with the tool and also to perform other configuration operations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Assembly Cache Viewer(Shfusion.dll) &lt;/strong&gt;This tool is used for viewing and manipulating the contents of the global assembly cache using the Windows explorer. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Assembly Linker (Al.exe)&lt;/strong&gt; &lt;br /&gt;This tool helps generate a file with an assembly manifest from one or more files that are either resource files or MISL files (Microsoft Intermediate Language files). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Assembly Registration Tool (Regasm.exe)&lt;/strong&gt; &lt;br /&gt;This tool is used to read the metadata within an assembly and adds the necessary entries to the registry. This in turn allows the COM clients to create .NET Framework classes transparently. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Assembly binding log viewer (Fuslogvw.exe)&lt;/strong&gt; &lt;br /&gt;This tool is used to display details of failed assembly binds so that users can diagnose why the .NET framework cannot locate an assembly at runtime. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CorFlags Conversion Tool (CorFlags.exe)&lt;/strong&gt; &lt;br /&gt;Allows you to configure the CorFlags section of the header of a portable executable image. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Global Assembly Cache Tool (Gacutil.exe)&lt;/strong&gt; &lt;br /&gt;Allows you to view and manipulate the contents of the global assembly cache and download cache. While Shfusion.dll provides similar functionality, you can use Gacutil.exe from build scripts, makefile files, and batch files. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Installer Tool (Installutil.exe)&lt;/strong&gt;&lt;br /&gt;This tool helps the user install or uninstall server resources by executing the installer components of a specified assembly. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Isolated Storage Tool (Storedm.exe)&lt;/strong&gt; &lt;br /&gt;Lists or removes all existing stores for the currently logged-on user.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Native Image Generator (Ngen.exe)&lt;/strong&gt; &lt;br /&gt;This tool creates a native image from a managed assembly and installs it in the native image cache on the local computer.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The .NET Framework Configuration Tool. (Mscorcfg.msc)&lt;/strong&gt;&lt;br /&gt;The .NET Framework security policy and applications that use remoting services are managed by this graphical user interface. The global assembly cache can be managed ant configured using this tool. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The .NET services Installation tool (Regsvcs.exe)&lt;/strong&gt;&lt;br /&gt;The managed classes are added to Windows 2000 component services using this tool. The services are loaded and registered into the assembly and the type libraries are generated, registered and installed into an existing COM + 1.0 application.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Serializer Generator Tool(Sgen.exe)&lt;/strong&gt;&lt;br /&gt;The XML serialization assembly for types in a specified assembly is created by this tool. This helps in improving runtime performance of the &lt;br /&gt;System.Xml.Serialization.XmlSerializer&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Soapsuds Tool (Soapsuds.exe)&lt;/strong&gt;&lt;br /&gt;This tool helps the user compile client applications that communicated with XML Web services using remoting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Type Library Exporter (Tlbexp.exe)&lt;/strong&gt;&lt;br /&gt;Generates a type library from a common language runtime assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Type Library Exporter (Tlbimp.exe)&lt;/strong&gt;&lt;br /&gt;The type definitions found within a COM type library is converted into equivalent definitions managed in metadata format.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Web Services Description Language tool. (Wsdl.exe)&lt;/strong&gt;&lt;br /&gt;This Generates code for XML Web services and XML Web services clients from Web Services Description Language (WSDL) contract files, XML Schema Definition (XSD) schema files, and .discomap discovery documents.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Web Services Discovery Tool (Disco.exe)&lt;/strong&gt;&lt;br /&gt;This tool is used to discover URLs of XML Webservices located on the server and saves documents related to the XML web service on a local disk.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;XML Schema Definition tool(Xsd.exe)&lt;/strong&gt;&lt;br /&gt;This tool helps generate XML schemas that follow th XSD language proposed by the World Wide Web Consortium (W3C). It also generates common runtime language classes and Data Set classes from an XSD schema file.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Microsoft CLR Debugger (DbgCLR.exe)&lt;/strong&gt;&lt;br /&gt;The graphical user interface provided by this tool helps application developers find and fix bugs in programs that target the runtime.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Runtime Debugger (Cordbg.exe)&lt;/strong&gt;&lt;br /&gt;This tool provides a command line debugging service that uses the Common Language Runtime Debug API to find and fix bugs in programs that target the runtime.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Certificate Creation Tool (Makecert.exe)&lt;/strong&gt;&lt;br /&gt;This tool generates X.509 certificates for testing purposes only.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Certificate Manager Tool (Certmgr.exe)&lt;/strong&gt;&lt;br /&gt;This tool Manages certificates, certificate trust lists (CTLs), and certificate revocation lists (CRLs).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Certificate Verification Tool (Chktrust.exe)&lt;/strong&gt;&lt;br /&gt;This tool is useful in the verification of the validity of a file signed with X.509 certification. This tool ships with the .NET Framework SDK version 1.0 and 1.1. For later versions users must use the Sign Tool (signtool.exe)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Code Access Security Policy Tool (Caspol.exe)&lt;/strong&gt;&lt;br /&gt;This tool allows users examine and modify machine, user, and enterprise-level code access security policies&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;File Signing Tool (Signcode.exe)&lt;/strong&gt;&lt;br /&gt;Signs a portable executable (PE) file with an Authenticode digital signature. The File Signing Tool only ships with the .NET Framework SDK version 1.0 and 1.1. In later versions of the .NET Framework SDK, use the Sign Tool (signtool.exe) utility instead.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Permissions View Tool (Permview.exe)&lt;/strong&gt;&lt;br /&gt;Displays the minimal, optional, and refused permission sets requested by an assembly. You can also use this tool to view all declarative security used by an assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PEVerify Tool (PEverify.exe)&lt;/strong&gt;&lt;br /&gt;Performs MSIL type safety verification checks and metadata validation checks on a specified assembly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Policy Migration Tool (Migpole.exe)&lt;/strong&gt;&lt;br /&gt;Migrates security policy between two compatible versions of the .NET Framework.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Secutil Tool (Secutil.exe)&lt;/strong&gt;&lt;br /&gt;Extracts strong name public key information or Authenticode publisher certificates from an assembly, in a format that can be incorporated into code.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Set Registry Tool (Setreg.exe)&lt;/strong&gt;&lt;br /&gt;Allows you to change the registry settings for the Software Publishing State keys, which control the behavior of the certificate verification process. The Set Registry tool only ships with the .NET Framework SDK version 1.0 and 1.1. In later versions of the .NET Framework SDK, use the Sign Tool (signtool.exe) utility instead.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Sign Tool (signtool.exe)&lt;/strong&gt;&lt;br /&gt;Digitally signs files, verifies signatures in files, and time stamps files.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Software Publisher Certificate Test Tool (Cert2spc.exe)&lt;/strong&gt;&lt;br /&gt;Creates, for test purposes only, a Software Publisher's Certificate (SPC) from one or more X.509 certificates.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Strong Name Tool (Sn.exe)&lt;/strong&gt;&lt;br /&gt;Helps create assemblies with strong names. Sn.exe provides options for key management, signature generation, and signature verification.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;License Compiler (Lc.exe)&lt;/strong&gt; &lt;br /&gt;Reads text files that contain licensing information and produces a .licenses file that can be embedded in a common language runtime executable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Management Strongly Typed Class Generator (Mgmtclassgen.exe)&lt;/strong&gt;&lt;br /&gt;Allows you to quickly generate an early-bound class in C#, Visual Basic, or JScript for a specified Windows Management Instrumentation (WMI) class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MSIL Assembler (Ilasm.exe)&lt;/strong&gt;&lt;br /&gt;Generates a PE file from Microsoft intermediate language (MSIL). You can run the resulting executable, which contains MSIL code and the required metadata, to determine whether the MSIL code performs as expected.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MSIL Disassembler (Ildasm.exe)&lt;/strong&gt; &lt;br /&gt;Takes a PE file that contains MSIL code and creates a text file suitable as input to the MSIL Assembler (Ilasm.exe). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Resource File Generator Tool (Resgen.exe)&lt;/strong&gt;&lt;br /&gt;Converts text files and .resx (XML-based resource format) files to .NET common language runtime binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Windows Forms ActiveX Control Importer (Aximp.exe)&lt;/strong&gt;&lt;br /&gt;Converts type definitions in a COM type library for an ActiveX control into a Windows Forms control.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Windows Forms Class Viewer (Wincv.exe)&lt;/strong&gt;&lt;br /&gt;Finds managed classes matching a specified search pattern, and displays information about those classes using the Reflection API. The Windows Forms Class Viewer only ships with the .NET Framework SDK version 1.0 and 1.1.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Windows Forms Resource Editor (Winres.exe)&lt;/strong&gt;&lt;br /&gt;Allows you to quickly and easily localize Windows Forms forms.&lt;br /&gt;&lt;br /&gt;------&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8699050161859053643-1801766651880996445?l=braindotnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://braindotnet.blogspot.com/feeds/1801766651880996445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8699050161859053643&amp;postID=1801766651880996445' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/1801766651880996445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8699050161859053643/posts/default/1801766651880996445'/><link rel='alternate' type='text/html' href='http://braindotnet.blogspot.com/2008/06/net-tools.html' title='.NET Tools'/><author><name>NMK</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://4.bp.blogspot.com/_xmdzLHNex7Q/TT2wSyxdHBI/AAAAAAAAAQc/gRq71s3LESY/s220/me4.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8699050161859053643.post-8510389305092999027</id><published>2008-06-03T03:11:00.000-07:00</published><updated>2008-12-09T16:00:24.014-08:00</updated><title type='text'>.NET General</title><content type='html'>&lt;strong&gt;.NET GENERAL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Microsoft.NET platform?&lt;/strong&gt;&lt;br /&gt;Microsoft .NET is a software development platform based on virtual machine based architecture. Dot net is designed from the scratch to support programming language independent application development. The entire .NET programs are independent of any particular operating system and physical hardware machine. They can run on any physical machine, running any operating system that contains the implementation of .NET Framework. The core component of the .NET framework is its Common Language Runtime (CLR), which provides the abstraction of execution environment (Physical machine and Operating System) and manages the overall execution of any of the .NET based program. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUdw8TOBqI/AAAAAAAAABQ/MkWZHT3TZgU/s1600-h/dotnetgeneral_html_243db46e.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUdw8TOBqI/AAAAAAAAABQ/MkWZHT3TZgU/s320/dotnetgeneral_html_243db46e.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207601270781511330" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;With dot NET, Microsoft introduces a completely new architecture for Windows applications (WinForm), Data Access (ADO.NET), Web Applications (ASP.NET), Windows components (Assemblies), Distributed Applications (.NET remoting), and above all the XML based Web Services. The famous figure for the representation of dot net is presented below: &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUej8TOBrI/AAAAAAAAABY/R4zV1QEwQLY/s1600-h/dotnetgeneral_html_215d3fbf.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUej8TOBrI/AAAAAAAAABY/R4zV1QEwQLY/s320/dotnetgeneral_html_215d3fbf.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207602146954839730" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the .NET framework?&lt;/strong&gt;&lt;br /&gt;The .NET framework is a collection of all the tools and utilities required to execute the .NET managed applications on a particular platform. The MS.NET framework includes the standard compilers (C#, VB.NET, J#, C++.NET, Jscript.NET), various utilities like (caspol, ngen, installutil, tlbimp, sn, asmreg, ildasm, etc), runtime environment (CLR), garbage collector, security manager, thread manager, assembly loader, just in time compilers, and the standard framework or base class libraries. It is important to realize that while the implementation of .Net applications is platform independent; the implementation of .NET framework is platform specific. In fact, it is this particular specific implementation of the .NET framework that makes the managed .NET applications platform independent.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What is the VB.NET and C# language comparisons?&lt;/strong&gt;&lt;br /&gt;VB.NET and C# both are integral part of the .NET framework. Both of the languages have a lot of similarities in language constructs and language design with minor differences in the syntax. C# is more like C++ and Java in its syntax while VB.NET lends its syntax from VB6 a great deal; although VB.NET can not be seen as the successor of Visual Basic at the level of overall language design and the vision of its creators. &lt;br /&gt;&lt;br /&gt;The general conception is that most of the VB6 developers will upgrade to VB.NET while developers coming from Java or C++ to .NET are likely to go for C#. Since web developers for Windows using ASP are familiar with VB and VB Scripts, therefore, most of the web development with ASP.NET at the start is likely to be dominated by VB.NET; but after sometime C# will be able to attract at least half of these developers. Keeping technical side away, C++ and thus C# developers are generally paid more than those of VB developers. So, this might also be the factor for making C# the language of choice on .NET framework. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between Console, Windows, Web applications and Web services?&lt;/strong&gt;&lt;br /&gt;Console applications are light weight programs run inside the command prompt (DOS) window. They are commonly used for test applications. &lt;br /&gt;&lt;br /&gt;Windows Applications are form based standard Windows desktop applications for common day to day tasks. Microsoft word is an example of a Windows application. &lt;br /&gt;&lt;br /&gt;Web applications are programs that used to run inside some web server (e.g., IIS) to fulfill the user requests over the http. A typical example of web application is Hotmail and Google. &lt;br /&gt;&lt;br /&gt;Web services are web applications that provide services to other applications over the internet. Google search engine’s web service, e.g., allows other applications to delegate the task of searching over the internet to Google web service and use the result produced by it in their own applications.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What is meant by language interoperability and language integration?&lt;/strong&gt;&lt;br /&gt;Prior to the introduction of .Net, the code written in one programming language is considered to be usable only in the programs written with the same programming languages. For example, an algorithm implemented in Perl programming language can not be reused in the programs written in the C++. At Windows platform, Microsoft introduced the standards for COM (Component Object Model) which allows components written in one programming language to be used in other programming language. In Java, JNI (Java Native Interface) is presented to use-up the code written in non-Java languages into Java programs. But both the standards (COM and JNI) are too complex and have their own limitations. They also don’t allow the language integration, which means that you can use the components written in other programming languages but you can’t extend the functionality of the components. &lt;br /&gt;&lt;br /&gt;In Microsoft.Net, the code written in any programming language is compiled to the same Intermediate Language (Microsoft Intermediate Language - MSIL or Common Intermediate Language – CIL) and to same component standard (assembly). Hence, it is possible for developers to employ the language interoperability by using and extending the solution implemented by other developers which might be using different programming language provided developers at both end are using.Net compliant programming languages. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a .Net Assembly?&lt;/strong&gt;&lt;br /&gt;The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution. &lt;br /&gt;&lt;br /&gt;There are two kind of assemblies in .NET; private and shared. Private assemblies are simple and copied with each calling assemblies in the calling assemblies folder. Shared assemblies (also called strong named assemblies) are copied to a single location (usually the Global assembly cache). For all calling assemblies within the same application, the same copy of the shared assembly is used from its original location. Hence, shared assemblies are not copied in the private folders of each calling assembly. Each shared assembly has a four part name including its face name, version, public key token and culture information. The public key token and version information makes it almost impossible for two different assemblies with the same name or for two similar assemblies with different version to mix with each other.&lt;br /&gt; &lt;br /&gt;An assembly can be a single file or it may consist of the multiple files. In case of multi-file, there is one master module containing the manifest while other assemblies exist as non-manifest modules. A module in .NET is a sub part of a multi-file .NET assembly. Assembly is one of the most interesting and extremely useful areas of .NET architecture along with reflections and attributes, but unfortunately very few people take interest in learning such theoretical looking topics. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the differences between a .NET Assembly, a Windows DLL and a COM Component?&lt;/strong&gt;&lt;br /&gt;A Windows DLL contains library code to be used by any program running on Windows. A DLL may contain either structured or object oriented libraries. &lt;br /&gt;&lt;br /&gt;COM (Component Object Model) is the component model based on the object oriented design, which means that the components represented by the COM component exists in the form of classes and objects implementing a standard specification defined by COM. COM components can be used by any program running on Windows Operating System; be it is written with VB, C++, Java or even some .NET compliant language like C# and VB.NET.&lt;br /&gt; &lt;br /&gt;Dot NET assembly is the component standard specified by the .NET. Hence, dot net assemblies are understandable to only Microsoft.NET and can be used only in .NET managed applications. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the differences between a .NET Assembly, a Windows DLL and a COM Component?&lt;/strong&gt;&lt;br /&gt;A Windows DLL contains library code to be used by any program running on Windows. A DLL may contain either structured or object oriented libraries. &lt;br /&gt;&lt;br /&gt;COM (Component Object Model) is the component model based on the object oriented design, which means that the components represented by the COM component exists in the form of classes and objects implementing a standard specification defined by COM. COM components can be used by any program running on Windows Operating System; be it is written with VB, C++, Java or even some .NET compliant language like C# and VB.NET. &lt;br /&gt;&lt;br /&gt;Dot NET assembly is the component standard specified by the .NET. Hence, dot net assemblies are understandable to only Microsoft.NET and can be used only in .NET managed applications. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between an executable assembly and a class library?&lt;/strong&gt;&lt;br /&gt;An executable assembly exists as the .exe file while a class library exists as the .dll file. Executable assembly represent executable applications having some entry (e.g., Main() method in C#). A class library, on the other hand, contains components and libraries to be used inside various applications. A Class library can not be executed and thus it does not have any entry point. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does one need to build or execute .NET applications?&lt;/strong&gt;&lt;br /&gt;To execute a standalone .NET application (Windows or Console application), one needs to first compile all its constituent assemblies and modules including the executable assembly. Once, the constituent assemblies are compiled, one needs to make sure that the target system contains the .NET framework. The application can now be executed by running its executable assembly (the .exe file). The executable assembly (.exe) is a Win32 executable that hosts the .Net CLR (Common Language Runtime), which exists as a COM component, in its process space and initializes it. Once the CLR is hosted and initialized, the starting point of the .NET executable assembly is passed to the hosted CLR which starts the execution of the program by translating and executing the parts of the program code.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What does it mean by managed code?&lt;/strong&gt;&lt;br /&gt;By managed code, it means that the complete life cycle and execution is managed by the .NET Common Language Runtime (CLR). The .NET CLR manages the memory on behalf of the managed code, performs garbage collection on the managed heap, perform assembly validation and assembly (component) resolution on behalf of the program. The CLR also maintains the security constraints applied to the managed code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is meant by un-safe code?&lt;/strong&gt;&lt;br /&gt;By un-safe code, it means that the managed program can access the memory address using pointers. There are two points to remember here; &lt;br /&gt;&lt;br /&gt;Un-safe code is different from un-managed as it is still managed by the CLR &lt;br /&gt;You still can not perform pointer arithmetic in un-safe code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between Unmanaged and Unsafe code?&lt;/strong&gt;&lt;br /&gt;Un-managed code runs outside the Common Language Runtime (CLR) control while the unsafe code runs inside the CLR’s control. Both un-safe and un-managed codes may use pointers and direct memory addresses. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What about the MS.NET standardization?&lt;/strong&gt;&lt;br /&gt;Microsoft has secured certification for both C# and CLI from ECMA and ISO/IEC as Industry standards. This is a very important step for Microsoft and .Net platform because this enhances the credibility of the newer .Net platform and allures a larger portion of technology industry into adopting .Net as their development platform. Several companies and government organizations only utilize ISO certified technologies; for example, in Australia anything ISO certified is also considered Australian standard according to the rules of the Australian government. Several academic institutions will now be interested in teaching standard C#. Another major outcome of having an open industry standard specification is .Net platform could be getting ported to other platforms like Linux and UNIX; best example is the Mono Project by Ximian- it is an open source implementation of .Net platform for UNIX and Linux based on ECMA approved Public Domain Specification of C# and CLI. &lt;br /&gt;&lt;br /&gt;Microsoft submitted the specifications to ECMA, which in turn fast-tracked them through ISO. In doing so, Microsoft released all intellectual property in the core C#/CLI platform to the public domain. No one needs a license to implement C#/CLI. This will also help everybody in better understanding the implementations of C# and CLI which are at the core of .Net platform. However, the whole of .Net platform is not a Public domain standard- Microsoft still owns complete Intellectual property rights to several class libraries and API within the .Net platform.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What about the implementation of .NET other than Microsoft.Net on Windows Operating System?&lt;/strong&gt;&lt;br /&gt;Microsoft has implemented .NET framework for all of its operating system suits (excluding MS Windows 95 and earlier) on all supported hardware platforms. For handheld and small devices, Microsoft has released a compact framework of .NET (http://msdn.microsoft.com/vstudio/device/compact.aspx ). But, there are various other implementations being developed on platforms other than Microsoft Windows. You can read the discussion on the portability of .NET at (See http://zdnet.com.com/2100-1107-960049.html) &lt;br /&gt;&lt;br /&gt;The most popular implementation, after MS.NET, is the open source ‘Mono’ Project on Linux (See www.go-mono.com) &lt;br /&gt;&lt;br /&gt;Microsoft has released almost all the source code of their .NET framework for FreeBSD and Mac OS under the title of Shared Source Common Language Infrastructure (SSCLI). Check out the SSCLI 1.0 release - which already builds on WindowsXP, FreeBSD, and Mac OS X 10.2, released under Microsoft's Shared Source Initiative. http://msdn.microsoft.com/net/sscli/ http://www.microsoft.com/resources/sharedsource/default.mspx &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between traditional development and .NET development?&lt;/strong&gt;&lt;br /&gt;In traditional programming languages, the source code of a program is compiled to a specific platform’s assembly language and then machine language code. Later the library code required by the program is linked to it. Finally the operating system executes the program when desired by the user. The complete process is depicted in the following figure: &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUiIsTOBsI/AAAAAAAAABg/IYs6jVK30TM/s1600-h/dotnetgeneral_html_m25fafccd.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUiIsTOBsI/AAAAAAAAABg/IYs6jVK30TM/s320/dotnetgeneral_html_m25fafccd.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207606076849915586" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the presence of dot net framework, a program is not compiled to the native machine executable code; rather it gets compiled to an intermediate language code called Microsoft Intermediate Language (MSIL) or Common Intermediate Language (CIL). The Dot Net Common Language Runtime (CLR) then converts this intermediate code at runtime to the machine executable code. The optimization is carried out at runtime. A program also does not call the operating system APIs directly; rather it delegates this task to the CLR which performs the desired operations on behalf of the program and returns the results of the operations back to the program. The CLR also performs the memory management, garbage collection, security and thread management on behalf of the program. Dot NET framework is shipped with the supporting object oriented framework of common code libraries, called the .NET Framework Class Library (FCL), to facilitate the common operations. Hence the .Net manages the overall execution of an application. This is the reason why the code running on .Net framework is sometimes called the managed code. The complete process is depicted in the following Figure. Note that only the CLR (and thus the .Net framework and not the user application) is interacting and coupled with the platform and operating system. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_xmdzLHNex7Q/SEUj-cTOBtI/AAAAAAAAABo/drLQ2-22-Bw/s1600-h/dotnetgeneral_html_m39e77080.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_xmdzLHNex7Q/SEUj-cTOBtI/AAAAAAAAABo/drLQ2-22-Bw/s320/dotnetgeneral_html_m39e77080.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207608099779512018" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the basic components of .NET platform?&lt;/strong&gt;&lt;br /&gt;The basic components of .NET platform (framework) are: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Common Language Runtime (CLR):&lt;/strong&gt;&lt;br /&gt;The most important part of the .NET Framework is the .Net Common Language Runtime (CLR) also called .Net Runtime in short. It is a framework layer that resides above the Operating System and handles/manages the execution of the .NET applications. Our .Net programs don’t directly communicate with the Operating System but through CLR &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUj-sTOBuI/AAAAAAAAABw/bwhcSkLfAnk/s1600-h/dotnetgeneral_html_7cbcb774.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUj-sTOBuI/AAAAAAAAABw/bwhcSkLfAnk/s320/dotnetgeneral_html_7cbcb774.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207608104074479330" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;MSIL (Microsoft Intermediate Language) Code:&lt;/strong&gt;&lt;br /&gt;When we compile our .Net Program using any .Net compliant language like (C#, VB.NET, C++.NET) it does not get converted into the executable binary code but to an intermediate code, called MSIL or IL in short, understandable by CLR. MSIL is an OS and H/w independent code. When the program needs to be executed, this MSIL or intermediate code is converted to binary executable code, called native code. The presence of IL makes it possible the Cross Language Relationship as all the .Net compliant languages produce the similar standard IL code. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUj-sTOBvI/AAAAAAAAAB4/XM8EHa9ugdo/s1600-h/dotnetgeneral_html_21d0e16.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_xmdzLHNex7Q/SEUj-sTOBvI/AAAAAAAAAB4/XM8EHa9ugdo/s320/dotnetgeneral_html_21d0e16.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207608104074479346" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Just In Time Compilers (JITers)&lt;/strong&gt;&lt;br /&gt;When our IL compiled code needs to be executed, CLR invokes JIT compilers which compile the IL code to native executable code (.exe or .dll) for the specific machine and OS. JITers in many ways are different from traditional compilers as they, as their name suggests, compile the IL to native code only when desired e.g., when a function is called, IL of function’s body is converted to native code; just in time of need. So, the part of code that is not used by particular run is not converted to native code. If some IL code is converted to native code then the next time when its needed to be used, the CLR uses the same copy without re-compiling. So, if a program runs for sometime, then it won’t have any just in time performance penalty. As JITers are aware of processor and OS exactly at runtime, they can optimize the code extremely efficiently resulting in very robust applications. Also, since JITer knows the exact current state of executable code, they can also optimize the code by in-lining small function calls (like replacing body of small function when its called in a loop, saving the function call time). Although, Microsoft stated that C# and .Net are not competing with languages like C++ in efficiency, speed of execution, JITers can make your code even faster than C++ code in some cases when program is run over extended period of time (like web-servers). &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Framework Class Library (FCL)&lt;/strong&gt;&lt;br /&gt;.NET Framework provides huge set of Framework (or Base) Class Library (FCL) for common, usual tasks. FCL contains thousands of classes to provide the access to Windows API and common functions like String Manipulation, Common Data Structures, IO, Streams, Threads, Security, Network Programming, Windows Programming, Web Programming, Data Access, etc. It is simply the largest standard library ever shipped with any development environment or programming language. The best part of this library is they follow extremely efficient OO design (design patterns) making their access and use very simple and predictable. You can use the classes in FCL in your program just as you use any other class and can even apply inheritance and polymorphism on these. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Common Language Specification (CLS)&lt;/strong&gt;&lt;br /&gt;Earlier we used the term ‘.NET Compliant Language’ and stated that all the .NET compliant languages can make use of CLR and FCL. But what makes a language ‘.NET compliant language’? The answer is Common Language Specification (CLS). Microsoft has released a small set of specification that each language should meet to qualify as a .NET Compliant Language. As IL is a very rich language, it is not necessary for a language to implement all the IL functionality, rather it meets the small subset of it, CLS, to qualify as a .NET compliant language, which is the reason why so many languages (procedural and OO) are now running under .Net umbrella. CLS basically addresses to language design issues and lays certain standards like there should be no global function declaration, no pointers, no multiple inheritance and things like that. The important point to note here is that if you keep your code within CLS boundary, your code is guaranteed to be usable in any other .Net language.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Common Type System (CTS)&lt;/strong&gt;&lt;br /&gt;.NET also defines a Common Type System (CTS). Like CLS, CTS is also a set of standards. CTS defines the basic data types that IL understands. Each .NET compliant language should map its data types to these standard data types. This makes it possible for the 2 languages to communicate with each other by passing/receiving parameters to/from each other. For example, CTS defines a type Int32, an integral data type of 32 bits (4 bytes) which is mapped by C# through int and VB.Net through its Integer data type. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Garbage Collector (GC)&lt;/strong&gt;&lt;br /&gt;CLR also contains Garbage Collector (GC) which runs in a low-priority thread and checks for un-referenced dynamically allocated memory space. If it finds some data that is no more referenced by any variable/reference, it re-claims it and returns the occupied memory back to the Operating System; so that it can be used by other programs as necessary. The presence of standard Garbage Collector frees the programmer from keeping track of dangling data. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the software development and execution flow in Microsoft.NET?&lt;/strong&gt;&lt;br /&gt;With .NET development environment, a developer can write his/her code in any .NET compliant programming language like C#, VB.NET, J#, C++.NET, etc. In fact, various modules, components, projects of an application can be written and compiled in different .Net based programming languages. All these components are compiled to the same Intermediate language code (MSIL or CIL) understandable by the .NET CLR. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUj-8TOBwI/AAAAAAAAACA/s_moqFDZp38/s1600-h/dotnetgeneral_html_90b6cec.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_xmdzLHNex7Q/SEUj-8TOBwI/AAAAAAAAACA/s_moqFDZp38/s320/dotnetgeneral_html_90b6cec.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5207608108369446658" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;At runtime, the .NET assembly (compiled IL code) is translated to native machine code and executed by the CLR. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How is MS.NET compared with Java based platforms (J2EE)?&lt;/strong&gt;&lt;br /&gt;At root level architecture and components, MS.NET and J2EE platforms are very similar. Both are virtual machine based architecture having CLR and Java Virtual Machine (JVM) as the underlying virtual machine for the management and execution of programs. Both provide memory, security and thread management on behalf of the program and both try to decouple the applications with the execution environment (OS and physical machine). Both, basically, target the Web based applications and especially the XML based web services. Both provide managed access to memory and no direct access to memory is allowed to their managed applications. &lt;br /&gt;However, there are few contrasts in the architecture and design of the two virtual machines. Microsoft .NET framework’s architecture is more coupled to the Microsoft Windows Operating System which makes it difficult to implement it on various operating systems and physical machines. Java, on the other hand, is available on almost all major platforms. At the darker side, J2EE architecture and JVM is more coupled to the Java programming language while Microsoft.NET has been designed from the scratch to support language independence and language integration. Microsoft.NET covers the component development and integration in much more detail than Java. The versioning policy of .NET is simply the best implemented versioning solution in the software development history. Java has got the support of industry giants like Sun, IBM, Apache and Oracle while the Microsoft.NET is supported by giants like Microsoft, Intel, and HP. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why should one use MS.NET for software development?&lt;/strong&gt;&lt;br /&gt;Well, most of the software development all over the world is done on and for Microsoft Windows Operating System. Dot Net is now the standard software development environment for the Microsoft Windows operating system. It dramatically simplifies the development of windows, web based, data access applications, components, controls and web services. Dot net comes with amazing features like XML configuration, reflection, and attributes to ease the overall software development life cycle. Finally, the dot net is supported by the Microsoft Visual Studio Integrated Development Environment; the best IDE available for any software development environment. Visual Studio .NET (VS.NET) supports all the areas of software development from project creation to debugging and installation. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the shortcomings of MS.NET platform?&lt;/strong&gt;&lt;br /&gt;The foremost short coming of .NET platform is that it is still the propriety of Microsoft. It is more coupled with the Microsoft Windows operating system and is implemented only on Microsoft Windows successfully. MS.NET desktop applications can run only on Microsoft Windows, Web based applications and web services can only be deployed on Microsoft Internet Information Server (IIS). Since, dot net framework contains a lot of utilities, components, and framework class libraries, the size of downloadable framework is quite large (25MB compared to 5MB size of JVM). Not all types of applications can be written in .NET managed applications, for example, you can’t write CLR or Operating System in your managed applications. The managed .Net applications are somewhat slower to start and run than the traditional Win32 applications. The compiled code of .Net managed applications is easier to de-compile back to the source code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How true it is that .NET and Java programs are quite in-efficient when compared to C++?&lt;/strong&gt;&lt;br /&gt;The startup of managed .NET and Java programs is definitely slower than the traditional C++ programs as it involves the hosting of CLR into managed application process in .NET and starting the JVM in a new process in case of Java. The execution also is a bit slower during the initial period of program execution as the intermediate code is translated to the machine code on the fly at runtime. But as the program runs various parts repeatedly, the execution gets pace too. Since, the CLR and JVM optimizes the code more efficiently than the static C++ compilers, the execution speed of the program may actually be faster after sometime of the program startup when most of the code is translated. Hence, in the longer run, the .Net and Java based programs should not be in-efficient when compared to C++. We used ‘should’ here as the actual performance depends on the particular implementation and implementation strategy. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are XML Doc comments (comments start with three slashes ///)?&lt;/strong&gt;&lt;br /&gt;The XML Doc comments are special kind of comments that can be recognized by Document utility to automatically generate the documentation of your methods, types and regions. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using COM components in .NET and How to add a reference to a COM component?&lt;/strong&gt;&lt;br /&gt;The .NET does not encourage the use of COM component directly inside the managed application! Although, the .NET framework contains utilities that enable COM components to be used inside the .Net applications seamlessly. How it is done? The .NET utilities like TlbImp generates the wrapper .NET assembly for the COM component which provides the same calling interface to the client as exposed by the COM component. Inside the wrapper methods, it calls the actual methods of the COM component and returns the result back to the caller. The generated wrapper .NET assembly is called the ‘Runtime Callable Wrapper’ or RCW. &lt;br /&gt;To use a COM component in your Visual Studio.NET project, you need to add a reference of the COM component in the Reference node of the project node of the solution inside the solution explorer window. The great thing about Visual Studio.Net is that it allows you to add a reference to the COM component in exactly the similar way as you add the reference to the .NET assembly. The Visual Studio.NET automatically creates the runtime callable wrapper assembly for the referenced COM component. &lt;br /&gt;To add a reference to a COM component, right click the ‘Reference’ node under the project node inside the solution explorer and select the ‘Add Reference…’ option. It will show you a user interface screen where you browse for the target COM component. When you have selected the component, press the ‘Select’ button and then press OK. This will add a new reference node in the Reference sub tree of the project. By selecting the added reference node, you can edit its properties from the properties window. &lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; The process of importing a COM component into .NET is called ‘COM interoperability with .NET’&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;What is .NET Framework and what are CLR, CTS and CLS?&lt;/strong&gt;&lt;br /&gt;. NET is a software platform. It's a language-neutral environment for developing .NET applications that can easily and securely operate within it.&lt;br /&gt; &lt;br /&gt;The .NET Framework has two main components: the Common Language Runtime (CLR) and the .NET Framework class library. &lt;br /&gt;&lt;br /&gt;The Runtime can be considered an agent that manages code at execution time. Thus providing core services such as memory management, thread management, and remoting. Also incorporating strict type safety, security and robustness. &lt;br /&gt;&lt;br /&gt;The class library is a comprehensive collection of reusable types that you can use to develop traditional command-line, WinForm (graphical user interface) applications, Web Forms and XML Web services. &lt;br /&gt;&lt;br /&gt;The .NET Framework provides a Runtime environment called the Common Language Runtime or (CLR) that handles the execution of the code and provides useful services for the implementation of the application. CLR takes care of code management upon program execution and provides various services such as memory management, thread management, security management and other system services. The managed code targets CLR benefits by using useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging. &lt;br /&gt;&lt;br /&gt;Common Type System (CTS) describes how types are declared, used and managed. CTS facilitates cross-language integration, type safety, and high performance code execution. The CLS is a specification that defines the rules to support language integration. This is done in such a way, that programs written in any language (.NET compliant) can interoperate with one another. This also can take full advantage of inheritance, polymorphism, exceptions, and other features. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is MSIL / IL? What is JIT (Just In Time)?&lt;/strong&gt;&lt;br /&gt;When compiling the source code to managed code, the compiler translates the source into Microsoft intermediate language (MSIL). This is a CPU-independent set of instructions that can efficiently be converted to native code. Microsoft intermediate language (MSIL) is a translation used as the output of a number of compilers. It is the input to a just-in-time (JIT) compiler. The Common Language Runtime includes a JIT compiler for the conversion of MSIL to native code. &lt;br /&gt;&lt;br /&gt;Before Microsoft Intermediate Language (MSIL) can be executed it, must be converted by the .NET Framework just-in-time (JIT) compiler to native code. This is CPU-specific code that runs on the same computer architecture as the JIT compiler. Rather than using time and memory to convert all of the MSIL in a portable executable (PE) file to native code. It converts the MSIL as needed whilst executing, then caches the resulting native code so its accessible for any subsequent calls. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Code Access Security (CAS)? How does CAS work? Who defines the CAS code groups?&lt;/strong&gt;&lt;br /&gt;Code Access Security (CAS) is part of the .NET security model. CAS determines whether or not a piece of code is allowed to run and also what resources to use. For example, CAS will prevent malicious code from entering your system and causing havoc. &lt;br /&gt;&lt;br /&gt;The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group and each code group is granted the permissions specified in a named permission set. An example: Using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group which complies to the permissions defined by the 'Internet' named permission set. &lt;br /&gt;&lt;br /&gt;Microsoft defines some default policies but you can modify these and even create your own. To view the code groups defined on your system; Run 'caspol' from the command-line and checkout the different options on display.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is serialization in .NET and what are the ways to control serialization?&lt;/strong&gt;&lt;br /&gt;Serialization is the process of converting an object into a stream of bytes. On the other hand Deserialization is the process of creating an object from a stream of bytes. Serialization/Deserialization is used to transport or to persist objects. Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly are converted to a stream of bytes. Which is then written to a data stream. Upon the object's subsequent deserialized, an exact clone of the original object is created. &lt;br /&gt;&lt;br /&gt;Binary serialization preserves Type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example: An object can be shared between different applications by serializing it to the clipboard. &lt;br /&gt;&lt;br /&gt;You can serialize an object to a stream, disk, memory, over a network, and so forth. Remoting uses serialization to pass objects "By Value" from one computer or application domain to another. XML serialization serializes only public properties and fields and does not preserve Type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data.&lt;br /&gt; &lt;br /&gt;As XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is also an open standard, which makes it an attractive choice too. There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Active Directory? What namespace should I use to use Active Directories?&lt;/strong&gt;&lt;br /&gt;Active Directory Service Interfaces (ADSI) is a programmatic interface for the Microsoft Windows Active Directory. It enables your applications to interact with different directories on a network using a single interface. &lt;br /&gt;&lt;br /&gt;Visual Studio .NET and the .NET Framework make it easy to add ADSI functionality with the DirectoryEntry and DirectorySearcher components. Using ADSI you can create applications that perform common administrative tasks, such as backing up databases, accessing printers and managing user accounts. ADSI allows: &lt;br /&gt;&lt;br /&gt;1) Log on once to work with diverse directories. The DirectoryEntry component class provides username and password properties that can be entered at Runtime and are passed to the Active Directory object you are bound to. &lt;br /&gt;&lt;br /&gt;2) Use of an Application-Programming Interface (API) to perform tasks on multiple directory systems. This includes multi protocol support. The DirectoryServices namespace provides the classes to perform most administrative functions such as creating users. &lt;br /&gt;&lt;br /&gt;3) Perform "Rich Querying" on directory systems. ADSI technology supports searching for objects with two query dialects: SQL and LDAP. &lt;br /&gt;&lt;br /&gt;4) Access and use a single or hierarchical tree structure for administering and maintaining a diverse and complicated network. &lt;br /&gt;&lt;br /&gt;5) Integrate directory information with databases such as  ?SQL Server. The DirectoryEntry path may be used as an ADO.NET connection string. &lt;br /&gt;&lt;br /&gt;Name space to be imported when working with Active Directories: &lt;br /&gt;System.DirectoryServices&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can I use the Win32 API from a .NET Framework program?&lt;/strong&gt;&lt;br /&gt;Using platform invoke it's possible. .NET Framework programs can access native code libraries by means of static DLL entry points. &lt;br /&gt;Here is an example of C# calling the Win32 MessageBox function: &lt;br /&gt; &lt;br /&gt;using System; &
