Friday, September 28, 2007

Cross domain XHRs and Localhost vs.

As of today, cross Domain XHRs are not "allowed" either in IE 7.0(?) or Firefox .   While testing this, I came across a very interesting find.

Firefox is so strict that it even treats ‘localhost’ and ‘’ as being different domains.  Here's a screenshot of the message from Firebug:


 IE [6.0] on the other hand is a very permissive [some would argue less secure]. It just displays a security dialog [even for a HTTP Get/Post to] and if user clicks 'Yes', it ALLOWS even Cross domain XHRs.



Technorati Tags: , , ,

Tuesday, September 25, 2007

Update: XmlHttpRequest Connection Pool

It seems that the 2 connection limit is as per HTTP 1..1 specification and not really a limitation of IE.

Monday, September 24, 2007

Firefox & XmlHttp Connection Pool?

Now, does Firefox pools XmlHttp connections? 

[Matter of just copying ssmoz.js to the App_Scripts folder to support firefox :)  I'm beginning to love Script#]

Here's the test result:


It's very similar to the IE results!  Now, does this mean, firefox does the same thing OR should I go back to debugging my test harness???  Guess, I'll wait and watch....

Technorati Tags: , ,

Using Script# to verify IE XmlHttp Connection Pool

IE pools XMLHttp connections.  To quote the new "ASP.Net Ajax in Action" book verbatim:

Another interesting tidbit is that in IE, only two connections
can be opened at a time...

Question: Now, How do I verify this?

Answer: How about opening a multiple connections to a long running query?

This was precisely what I had done.  I had IE open XmlHttp requests to a


Here are the results:


The operation had the thread wait for 10 seconds at the server.  Now look at how the results are clumped by two.  So IE QUEUEs all your async XmlHttp requests (I assume it allows as many as you want to open... The test opened 10 as shown above), and services them by a pool of 2 XmlHttp objects.

Script# and Nikhil, you guys rock :)

Technorati Tags: , ,

Script# Gottchas [2] - Thine Code Shall Compile

Well, again, when you're using Scriptlet server control and the Script# source editor, you need to make sure that you get the below dialog when you hit 'Compile' button:



I cannot overstress the importance of getting your code to compile properly.  Otherwise, you'd be chasing phantom errors and incomplete source file generation [Tip: Turn off script debugging in IE for you to get the complete source to examine].

Technorati Tags:

Script# Gottchas [1] - Thine Code Shall Compile

I've been toying with Nikhil's Script# for the past week.  There's a learning curve involved.  While the documentation is very helpful and covers almost all scenarios, it does have few issues.  For one, the screenshots in the documentation pertain to an old version.  And the other, it doesn't spoon-feed you!  [How we miss getting spoon-fed, uh?  Thank you, MSDN]...

Nikhil does a very good job of warning you that the Csharp code must compile.  But he does not, of course, tell you want would happen otherwise.

Look at the seemingly innocuous code below:

    1 using System;
    3 namespace NewNameSpace
    4 {
    5     public class Reverser
    6     {
    7         public static void Main(string[] args)
    8         {
    9             Console.WriteLine(Reverse(args[0]));
   10         }
   12         public static string Reverse(string str)
   13         {
   14             char[] chars = str.ToCharArray();
   15             Array.Reverse(chars);
   16             return new string(chars);
   17         }
   19     }
   20 }

The above code is valid C# [Of course ;)].   What is more interesting is that even the Script# compiler doesn't complain.


Here's the Javascript generated:

    1 Type.createNamespace('NewNameSpace');
    3 ////////////////////////////////////////////////////////////////////////////////
    4 // NewNameSpace.Reverser
    6 NewNameSpace.Reverser = function() {
    7 }
    8 NewNameSpace.Reverser.main = function(args) {


What the heck?  Where's the rest of the file!!!

My initial reaction is that Nikhil has forgotten to write a fileBuffer.Flush() somewhere ;) [from the guy who wrote a compiler?  Forget it :)]

Hidden in the recesses somewhere [I don't remember where] there was an ominous line warning that your code MUST compile before you can turn Script# compiler on it.

To cut the long story short, you need to compile your C# code with:



Technorati Tags:

Thursday, September 20, 2007

VS.Net 2005 SP1 - How to tell?

I ran into an interesting issue couple of days back... I had VS.Net 2005 reinstalled by my company's IT services.  Now, I wanted to know whether they had installed SP1 or not!  Searched the net and came up dry...

  • Your about box should have the version numbers like the one below [The version before SP1 was 8.0.50727.42]


  • Your HKLM\Software\Microsoft\DevDiv\VS\Servicing\8.0\VSTD\1033 registry key should resemble the one below [See the highlighted keys]



Wednesday, September 19, 2007

Windows Live Writer Rocks! And Ecto for Windows?

Past few posts have been posted using Windows Live Writer...  It definitely rocks!  Once I had the Flickr plug-in, even posting images - which is a general complaint from folks trying Live Writer for the first time - was a breeze.

Can you imagine I had bought Ecto for about $15!  Well, it was SO buggy that within 15 minutes of buying it I had to send them my bug report with detailed screenshots.  Of course, they did fix it and send me a DEBUG build.  But it was giving me some other issues!   Finally, I had requested for a refund which they were gracious enough to grant me :)

Windows Live Writer Team, Thank you guys.


Technorati Tags: , ,

Conditional("DEBUG") and Compiler Optimizations

OK... One interesting aside:


See, how compiler had optimized the ENTIRE constructor away?  This is what is so very powerful.  Because Conditional("DEBUG") statements disappear on a RELEASE build, the compiler is free to optimize your code in ways it sees fit.

The results of compiling with optimizations  turned off:

 c:\>csc /optimize- /t:library ifdebug.cs



Here the compiler preserves your empty constructor.  We'll touch upon these points once again in forthcoming posts.

#if DEBUG vs. [Conditional("DEBUG")]

    1 using System;
    2 using System.Diagnostics;
    3 public class IFDebug
    4 {
    5 #if DEBUG 
    6   public int Method ()
    7   {
    8     return 5;
    9   }
   11 #endif
   12     //error CS0578: The Conditional attribute is not valid on 
   13     //'IFDebug.Method2()' because its return type is not void 
   14     /* 
   15   [Conditional("DEBUG")] 
   16   public int Method2() 
   17   { 
   18   return 5; 
   19   }*/
   20 #if DEBUG 
   21   public void Method3 ()
   22   {
   23   }
   25 #endif
   26     [Conditional("DEBUG")]
   27     public static void Method4()
   28     {
   29     }
   31 }
   34 #if DEBUG 
   35 public class IFDebug2 {
   36 }
   39 #endif
   40 //ifdebug.cs(28,2): error CS1689: Attribute 
   41 //'System.Diagnostics.ConditionalAttribute' is
   42 //only valid on methods or attribute classes 
   43 /* 
   44 [Conditional("DEBUG")] 
   45 public class IFDebug3 
   46 { 
   47 }*/
   48 //So, let's compare apples to apples 
   49 #if DEBUG 
   50 public class IFDebug3 : Attribute{
   51 }
   52 #endif
   54 [Conditional("DEBUG")]
   55 public class IFDebug4 : Attribute
   56 {
   57     public IFDebug4()
   58     {
   59         IFDebug.Method4();
   60     }
   62 }

Consider the above code.  Let's say I compile it with

c:\> csc /t:library /define:DEBUG ifdebug.cs

The ILDASM screenshot looks like this:



What if I do a RELEASE build?



So, it simply means that [Conditional("DEBUG")] classes get carried to RELEASE builds.  But is that all?  Nope... Calls to methods adorned with Conditional("DEBUG"), evaporate - disappear - in RELEASE builds.  Here are the screenshots from Reflector:


ifdebug-7 ifdebug-8

How is it useful?  Practical usage?  Wait for my next post :)