Code Library.... C# | Microsoft.Net

Difference between HTML 4 and HTML 5

HTML (Hypertext Markup Language) is actually used as a common language to instruct the browsers on how to logically structure a web page through its own syntax and semantics..

So What is HTML 5 or what is the difference between HTML 4 and HTML 5 ?

HTML 5 is nothing but a revised higher version of existing HTML 4 (HTML Version 4) with some addition of elements and semantics to it so that we can directly accomplish some of the tasks which we were doing through some work around in HTML 4.

For example, if you to display a video, you would be using DIV tags in the older HTML and specify a href target and browser never know that you are intending to display a video and thus for displaying a video preview, you may depend on add-ons or some JavaScript based hacks or flash. [More]

MEF... (Managed Extensibility Framework)

MEF is now a part of .Net 4.0,

MEF was around the corner for nearly some time now and it was available as one of the open source framework in Microsoft’s open source community. ( ). Now with lot of modifications and a finishing touch, it has been added as a new feature in Microsoft .Net 4.0. (Packed with Visual studio 2010)

So what is MEF or Managed Extensibility Framework? What is it actual use?

To answer, Managed Extensibility Framework (MEF) is a new library in .NET Framework 4 and Silverlight 4 that addresses the design problem of extensibility to some extend by allowing application to discover and use MEF extensions without using any configuration files. Here the application receiving extensions also should be MEF compatible and it will search for the MEF extensions on a particular path which is again declared inside the main application by any of the following ways [More]

String Interning in .net

We all know that the way .net handles a string is not optimal and uses up lot of memory, thought there are reason to do like this. But if we have more string objects or comparison inside our assembly then in this case surely it is going to be a performance hit. But here what really happens is framework itself take cares at least some part of it using the concept of Sting Interning

It seems that there is an internal hashtable maintained with the actual string value and it’s reference to managed heap. And two methods help us to handle this hash table

This is the “Intern” and “IsInterned” methods which is part of string manipulation class. [More]

A Generic and Dynamic way to invoke remote WCF/Webservice Web Method

I have written an article long back on Dynamic Web service Invoke and Code for dynamically generating web proxy. Any way that was not efficient to the core and hence I have re-written then code to satisfy both the conditions. The advantage of the below C# source code is that you don’t have to create proxy of any kind while using the below code (using SVCutil or WSDL). You can send a SOAP payload as it is, with whatever parameter contents it may have thus making it very easy to dynamically call a particular remote WCF/web method.

A SOAP payload is nothing but the XML serialized format of your data contract along with the standard SOAP header and footers added.

The Soapaction which you have passed determines the remote web method name which you want to invoke and SOAPAction should be exactly same as it appears in the WSDL of that particular webservice. and that should be enough to attache and invoke the remote web method. [More]

Get notified when garbage collections happens

This is a code snippet which i got from Jeffrey Richters blog. This code offers a way to raise notification event when a garbage collection occurs on Generation 0 or Generation 2 object

Here is the code for the class:

public static class GCNotification {
private static Action s_gcDone = null; // The event’s field
public static event Action GCDone {
add {
// If there were no registered delegates before, start reporting notifications now
if (s_gcDone == null) { new GenObject(0); new GenObject(2); }
s_gcDone += value;
remove { s_gcDone -= value; } [More]

Listing down remote WCF/Webservice methods by parsing WSDL at runtime

Here in this article I will describe (as well as provide the C# source code) on how to list down all the methods hosted in a given web service in situations where the only thing in your hand would web service URL and nothing else. You can access the WSDL file of that web service/ WCF service; dynamically query and parse the WSDL at runtime , identify the web methods and it’s parameters and display where ever you want. It doesn’t matter whether the web service/ WCF is certificate protected, the below C# source code will help you to read, parse and list down all the methods. [More]

Thread Not working in When deployed to IIS

This is about a problem that i have faced during the development of an application. In a certain scenario there was a need for us to create multiple threads manually inside an application. We created this using the below code

Thread Th = new Thread (Myobj.mymethod)

Now everything worked fine as expected in Microsoft Visual Studio ide and there was no problem until i deployed my code in webserver which was IIS. After deploying to IIS the manual thread was not getting invoke or executed regardless whatever we do. These manual threads always used to get pre-empted or killed before it executes. It really took a while before we found out what exactly we need to do to make these threads work [More]

Few Type Casting fundamentals in Microsoft.Net

As you may know Microsoft .Net itself is a framework and it executes lots of checks in the backgroud to make use of the the best available resources in your computer system as well as to manage the Microsoft .Net code execution in a smooth way. So it is really needed that one should know a bit about how your Microsoft .Net code executes in .net CLR (common language runtime) managed environment. A few about the Microsoft .Net type casting scenarios and what actually CLR does during type casting are here. You can increase your Microsoft .Net C# code execution performance if you really concentrate on the facts like this.

Many of us used to check the incoming type of an object and normally we go for calling Getype method or using is keyword like [More]

Property Parser - or Reflection Query language Parser

So while you program, how many times you have to deal with big enough data contracts?. It is really complex If the data contract is having properties 6 or 10 levels deep and that too with arrays and indexers in it. (e.g. Inputrequest.client[0].orders[2].Products[5] .product details.blah.blah_blah). The complexity even increases when you have to check and make sure each of these properties or its array elements is not null before accessing or retrieving the values from them. So you may end up looping through all the properties and array elements before retrieving any value from it. Same holds true if you need to amend or insert any value for any of these array elements. And obviously you will be using the same or different data contracts in many places in your project where you have to repeat your validation. if you miss a null check in any of the places, you will get the most familiar “Object reference not set to instance of an object ” error [More]