M G Vinod Kumar\’s Technology Blog

October 12, 2007

Microsoft releasing source code for .NET Framework

Filed under: .NET — Tags: — mgvinod @ 12:32 pm

One of the big news that happened last week was that Microsoft is releasing their original source code for .NET Framework as a reference for all the developers. The only bad part is that it is only available from .NET 3.5 and Visual Studio 2008. Anyway, it is still some thing really to look forward to… Till then, I guess we just have to live with disassemblers like Reflector..

It will be also interesting to find out more the licensing under which they are release. Given it is Microsoft and their genetic make-up includes world domination and manipulation strands curled around each other, there must be something lurking under those small prints… so have a thorough read of it before using it in a firm.

For those who are interested in knowing more: http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx


May 1, 2007

Books, Reviews and Authors

Filed under: .NET, Books, WPF — mgvinod @ 9:56 am

Writing a book has always been a gateway to becoming famous. Its easy compared to many other ways and if your books really hit off with the public, then you are really famous. If nothing is working, then create a controversy or something of that sort. It brings in more publicity and attention, sells more books, and your bank balance becomes bigger. If you can’t create a controversy, let someone else do it. This doesn’t happen often in the world of writing technical books, but current speak of blogosphere is the feud between a well known author, Charles Petzold and not so well known, Adam Nathan about their books on WPF.

To cut the story short, it all began with a review of those two books by Jeff Atwood on his popular blog “Coding Horror”. Jeff was of the view Adam’s book is much better read because of the way it has been presented, with colors, bullet points etc. while Charles’ book is boring to read. Many comments poured in as well about the content, number of pages etc. This included many heavy weights such as Don Box. Charles hit back stating Adam’s is power point like. Adam took a humorous side to it and posted his take on it in his blog.

Anyway, I hope this whole episode will help in improving on how technical books are presented in future. I’m sure many publishers would have taken note of this duel.

Personally, I haven’t read book the books. So can’t comment on it. But from the blog comments that I have been posted, it looks like Jeff’s right and Adam’s book wins hands down.

February 23, 2007

.NET Error

Filed under: .NET, Debugging — mgvinod @ 11:14 am

Below is the complete error which I came across recently. I was stuck with it for hours and it could not have come at a worse time – UAT phase ready to sign off and go into production.

System.IO.FileNotFoundException: File or assembly name lz2ikglf.dll, or one of its dependencies, was not found.
File name: "lz2ikglf.dll"

at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, Type[] extraTypes)
at Microsoft.Practices.EnterpriseLibrary.Configuration.SerializerCache.GetSerializer(Type baseType, Type[] types)
at Microsoft.Practices.EnterpriseLibrary.Configuration.Transformer.XmlSerializerTransformer.CreateXmlSerializer(Type valueType)
at Microsoft.Practices.EnterpriseLibrary.Configuration.Transformer.XmlSerializerTransformer.Deserialize(Object section)
at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationBuilder.ReadConfiguration(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManager.GetConfiguration(String sectionName)

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\DOCUME~1\SVC_FC~1\LOCALS~1\Temp\1\lz2ikglf.dll
LOG: Appbase = T:\WorkUnitGenerator\
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/DOCUME~1/SVC_FC~1/LOCALS~1/Temp/1/lz2ikglf.dll.

Looking at the problem, it looks like the System.CodeDom.Compiler compiles the assembly and then while trying to load it back in, it cannot find the file. Hence the System.IO.FileNotFoundException thrown. First thing to check is the write permission on this directory. That seems to be not a problem.

After much googling, came across a suggestion to reinstall .NET framework again. Weird as it seems, on one of the machines, it seems to have done the trick. But on another it didn’t work.

So, if you come across this issue and none of the above worked, then try reinstalling OS. Have fun! 🙂 Also, don’t forget to leave comment about your experiences if you have come across this.

August 3, 2006

DateTime and IsEmpty

Filed under: .NET — mgvinod @ 11:29 am

I ran into a problem of checking whether a given DateTime is empty or not. Since DateTime is a value type, it is is initialised to {1/1/0001}(which is the MinValue), so checking for null reference won’t make sense, unless you are using NullableTypes. I did a search on google and ran into Eric Gunnerson’s post. He suggests using a new struct which checks for the emptiness.

public struct EmptyDateTime
    DateTime dateTime;

public EmptyDateTime(DateTime dateTime)
        this.dateTime = dateTime;

public bool IsEmpty
            return dateTime == DateTime.MinValue;

public static explicit operator DateTime(EmptyDateTime emptyDateTime)
        if (emptyDateTime.IsEmpty)
            throw new InvalidOperationException("DateTime is Empty");
        return emptyDateTime.dateTime;

public static implicit operator EmptyDateTime(DateTime dateTime)
        return new EmptyDateTime(dateTime);

public static EmptyDateTime Empty
            return new EmptyDateTime(DateTime.MinValue);

For those who are interested in the actual post:http://blogs.msdn.com/ericgu/archive/2004/03/23/95011.aspx

June 12, 2006

IsNumeric in C#

Filed under: .NET, Uncategorized — mgvinod @ 4:09 pm

C# doesn't have a IsNumeric or IsNumber on string object. So here are some implementations

Using Parse

public bool IsNumeric(string s)
            return false;
      return true;

Using char 

internal static bool IsNumeric(string numberString)
    foreach (char c in numberString)
        if (!char.IsNumber(c))
             return false;
   return true;

Using Regex

static bool IsNumeric(string inputString)
    return Regex.IsMatch(inputString, "^[0-9]+$");

If you are using C# 2.0, you may use TryParse Method

public static bool IsNumeric(object Expression)
    bool isNum;
   double retNum;
   isNum = Double.TryParse(Convert.ToString(Expression),   System.Globalization.NumberStyles.Any,System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
   return isNum;

May 19, 2006

Solving Sudoko

Filed under: Puzzles, Sudoko — mgvinod @ 10:30 am

If you are interested, it is difficult to not to get hooked on to Sudoko – the japanese number game. Even though you may have figured various techniques for solving the sudoko, this site gives you a proper guidance on it.

Hope you enjoy it.

April 25, 2006

HelloWorld WebService in Visual Express Editions

Filed under: .NET, Web Services — mgvinod @ 4:52 pm

Implementing and consuming a webservices using Visual Express editions is quite easy to do. You will need both Visual Web Developer Express edition and Visual C# edition installed. I won't delve into the details of the WebServices, just a quick start to get you going.

Creating a HelloWorld WebService

1. Using Visual Web Developer Express, create a new ASP.NET Web Service by File -> New Web Site…. Let us give a name of HelloWorldWebService and click OK.

2. By default, it should have created all files that are required including HelloWorld Method already implemented in Service.cs file. Open the file Service.asmx and you will see just one line of code.

3. Select the solution in the Solution Explorer and in the Properties window, set Use dynamic ports to False. If you wish to change the Port number, you may change it now. For me, it is showing 3697.

4. Press Ctrl+F5. This should build the solution and deploy the webservice using local development IIS that comes along with the express edition.

If you select the HelloWorld link, it should allow you to test the web service by click the Invoke button. It should open a web browser window with result as given below.

<?xml version="1.0" encoding="utf-8" ?>

<string xmlns="http://tempuri.org/">Hello World</string>

Leave the IIS running. You should be having a small icon in your system tray indicating that. Now, let us look at how to write a client to use this Web Service.

Consuming the HelloWorld WebService

1. Start Visual C# Express Edition. Create a new Console Application. (You may use window application also as your client application.) Let us name it as HelloWorldWebServiceClient.

2. Now Add Web Reference… by right clicking on the References in Solution Explorer. Enter the url


It should display the available opertions, in our case, it is HelloWorld. Click Add Reference. This should add localhost under the Web References folder in Solution Explorer.

Note: Ensure that the right Port number is mentioned.

3. Open the Program.cs and add the following code in the Main method.

localhost.Service service = new localhost.Service();

Console.WriteLine("Message Received: {0}", service.HelloWorld());

4. Press Ctrl+F5. This should build the solution and a message like this should be displayed in your console.

Message Received: Hello World

That's it.

April 24, 2006

Marker Pattern aka Marker Interface Pattern

Filed under: .NET, Pattern — mgvinod @ 10:22 am

The Marker Pattern is popularly known as Marker Interface Pattern. I removed the Interface since this pattern can be implemented in two ways. Let us consider each of the ways.

1. Using an interface

First an interface is created as given below.

interface ITransactionAware{


Then, the class implements the interface.


class ClassWithMarkerInterface : ITransactionAware{


Using reflection, class can be checked to whether it implements the interface or not. Based on that result, any required action can be taken.


ClassWithMarkerInterface clsInterface = new ClassWithMarkerInterface();

if (clsInterface is ITransactionAware){

//start transaction



2. Using an attribute

Instead of an interface, an attribute is used.

class TransactionAttribute : System.Attribute{


The class is then marked with the above attribute.



class ClassWithAttributeMarker {


The code to check for attribute is little more verbose than using the interface.


ClassWithAttributeMarker clsAttribute = new ClassWithAttributeMarker();

if (clsAttribute.GetType().IsDefined(typeof(TransactionAttribute),false)){

//start transaction



As you can see, using an attribute is slower than the normal interface. Purists would argue that an attribute should be used, but if performance is your top criteria then interfaces are the way.




Dispose pattern in depth

Filed under: .NET, Design Guidelines, Pattern — mgvinod @ 9:41 am

Dsipose pattern is one of the most often used and mentioned patterns within .NET world. If you are interested in knowing the details, you should read this from the source.

Enum Design Guidelines

Filed under: .NET, Design Guidelines — mgvinod @ 9:37 am

If you think there is not too much to think about while designing Enums, well, think again! Have a look at this blog entry  .

Older Posts »

Create a free website or blog at WordPress.com.