Ensure You Use The Release Version Of Library

September 1, 2010 14:56 by Anton

Yesterday I had an interesting experience, the web that we develop  suddenly became not responding. We predicted that this is because either database locking or too may request.

It turned out that an assertion from 3rd party library (PdfSharf) failed! So we need to click OK in web server pc first, then web continued as usual.

Honestly, I’ve never used Debug.Assert to check the state of my code, so this behavior surprises me.

It is a good practice to use the release version of 3rd party library.


Bad Experience With Assembly.LoadFile

August 21, 2010 18:41 by Anton

I’m working on web application with ASP.NET MVC and I use Castle MikroKernel as DI container. This is not my first time using MikroKernel,  but everything had been fine before.

This time the property injection didn’t work :( .

As a note, I develop custom XML schema to suit my need, so I don’t use Windsor’s XmlInterpreter class.  I  was sure that my component registration is ok, but I found that every time I build my application I need to close the existing Cassini web server. When I open my web , it said that one of my assemblies is still used by other process ?!

Something must be wrong with my dynamic loading. I checked my previous work and there I used Assembly.LoadFrom , not Assembly.LoadFile to load my plug-ins. But they sound similar, aren’t they?

Then I binged and I found this


You should never use Assembly.LoadFile()
Use LoadFrom() if you know where the assembly is located, use Load() to let .NET figure out where the assembly is located. 
Using Load() should be your preference but may require a .config file to help .NET find the assembly.

Inline Label Element Issue

August 14, 2010 14:25 by Anton

The difference between web browser always make developer’s life harder. I just noticed several days ago, after time consuming investigation for a simple UI problem (+/-30 mins) , that inline label element doesn’t work in Internet Explorer 7


.NET Framework 4.0 Size Is 48.1 MB ?!

April 25, 2010 06:05 by Anton

I haven’t installed Visual Studio 2010 yet, but according to Scott Hanselman, the redistributable size has been trimmed down to 48.1 MB

 

  3.5 SP 1 4.0
32 bit Client Profile 255 MB 28.8 MB
32 + 64 bit Client Profile - 42 MB
32 bit Full - 35.3 MB
32 + 64 bit Full - 48.1 MB
32 + i64 bit Full - 51.7 MB
32+64+i64 bit Full 231 MB -

This will definitely helps the deployment process.


Fun With Extension Method and Fluent Interface

April 13, 2010 07:01 by Anton

Since C# 3.0, object initializer has been my favourite.

Given the following class:

public class Book
{
    public string Isbn {get;set;}
    public string Title {get; set;}
    public string Author {get; set;}
    public int TotalPages {get;set;}
    public void Save()
    {
	//some persistent logic
    }
}

Prior to C# 3.0 you’ll normally use the following codes:

Book book=new Book();
book.Isbn="1284848395";
book.Title="What the hell?";
book.Author="Unknown";
book.TotalPages=40;
book.Save();

Tiresome, right? Consider the following statement:

new Book{
    Isbn="1284848395", Title="What the hell?",
    Author="Unknown",TotalPages=40
}.Save();

We get the same result with only 1 statement. Now what happened if your variable is not initialized directly, but taken from other method, let’s say getter or perhaps factory method. You’ll still need to code with old style. What if you are a fluent interface lover so you want 1 statement only.

We can use this.

public static T Do<T>(this T o,Action<T> action)
{
    action(o);
    return o;
}

Notice how we call it:

GetBook().Do<Book>(b=>{
   b.Isbn="1284848395"; b.Title="What the hell?"; 
   b.Author="Unknown";b.TotalPages=40;        
}).Save();

It is certainly more verbose, but if 1 statement is what you’re after then it works. You can also refactor anonymous method into a concrete method since it will make code cleaner.