Sunday, December 23, 2007

My New Rig - Part I : Shopping

Well, in Delhi - where I live - we have this famous place called "Nehru Place" where we get all our components.    It's the pilgrimage we undertake when we have a requirement for a new PC. 

You need to understand that in India we do not have the likes of Best Buy or Fry's or any such specialized chain stores.  We have a Hong Kong style - China style? - bazaar, an array of stores so small that it cannot fit a compact car, teeming with people that tries to sell everything from software [pirated, of course] to sleaze to laptops to pre-assembled computers to full blown parallel processing marvels.

Yeah, I see you rolling your eyes.  Ok, I'm stretching it a bit but only the last bit ;).  And for those patriots, ok, we are the next US of A.  We do starting to have stores such as eZone that specialize in computer components.

The point is, when you ask for some component with a number such as D975XBX2, it's  most likely the shop in question would make a couple of phone calls to determine availability [to one of the shops in the same complex, of course] and say why don't I buy Asus P5KC.  It's the new in thing that the rest of the Delhi is buying [, you moron].

Another beauty is that you have to make your decision, in a jiffy.  You see, there will be people - at least a dozen - jostling with you, shouting at the shop keeper for a DDR 2 RAM or a Microsoft Ergo mouse.  The shopkeeper's attention span is usually less than a two seconds.  He'll be juggling two phones and a cellular phone simultaneously talking to his customers and vendors and showing off his parallel processing capabilities.

Bottom line:   I did dutifully accept the offer of taking an S975XBX2 instead of the asked for D95XBX2.

Here's my final component list:

  • A pirate's version of  Apple's cabinet with handles
    • I couldn't find the link where I saw the apple's design.  Will provide it later.
  • Intel Core 2 Quad Q6600
  • SG975XBX2
  • Transcend 4 GB DDR II RAM [800 MHz]
    • 4 single pieces.  Surprise, Surprise!  The guy didn't have a 2 GB pieces of DDR II
  • No Graphics Card
  • No Sound Card
    • All the newer boards support 7.1 Surround which would suffice my needs.
  • Ethernet Card
    • Most of the above motherboards have LAN built-in

I purchased them about 3 weeks ago.  At last, got sometime to blog [with my darling daughter throwing things at me in the background].

Sunday, December 09, 2007

Scalability in Physics vs. Scalability in Computer Science

In my experience, I've seen that most of the solutions are just a restatement of their scale.  That is, scale and the solution is so intricately intertwined, that the solution is not applicable to the same problem of a larger scale.  Unless, of course, the solution keeps scale in mind [a solution that can be scaled up, and more importantly scaled out].

I saw this [couple of months ago]:  A nuclear reactor built in the basement.

Hmm... I'm no physicist, but it seems scalability in software is a unique problem ;)

 

Technorati Tags:

Saturday, December 08, 2007

My Proposed New Rig: Core 2 Quad 6600

I think it's time for a new rig for me.  This would be my third - DIY - custom built system (See:   Jeff's DIY evangelism).   My current one is a Intel Pentium 2.4 GHz HT.  Here's the complete configuration:

  • Intel Pentium 2.4 GHz HT
  • Intel D865GBF Motherboard
  • Nvidia GeForce 6200
    • More recent addition, after I installed Vista Enterprise on an auxiliary drive
  • 1 GB DDR RAM [400 MHz]
  • HDD
    • 120 GB Seagate Barracuda SATA
    • 150 GB Samsung SATA
    • Elements 300 GB [External, USB]
  • No Sound Card
    • I find the integrated audio enough for my needs [4.1 Surround]
  • Ethernet Card
  • Samsung SyncMaster 206BW 20" LCD
  • Sony DVD +- RW Writer
  • Sony DVD ROM
  • Kensington Wireless Keyboard, Mouse Combo
    • I had a Microsoft Natural Ergonomic Keyboard 4000.  I also have an imp for a daughter - 2 and half a year old.  She had a field day drenching it with a mouthful of water. 
  • Creative Ultra Webcam
  • Intex Headphones

I run the following OSs:

  • Windows XP SP2 [primary]
  • Windows Vista Enterprise  [Auxiliary]

My proposed rig:

Proposed OS:

  • Windows Vista Enterprise 64 Bit

My new machine would probably inherit everything else starting from SyncMaster down from my old machine.  Also planning to keep my old one around.

I'll do a Jeff Atwood in the coming week assembling my new rig.

Update: VS.Net 2008 Team Suite RTM

I'm still seeing only VS.Net 2008 trial as you can see below:

vsnet2008teamsuite

 

A brainwave struck me about ten minutes ago.  OK!  Only trial is available for download but I read somewhere the trial or full version is determined by the product key - obviously!  This is what I'm seeing when I  went the Product Keys page:

 

vsnetkeys

 

It talks about VS.Net rather than VS.Net 2005 / VS.Net 2008.  I reckon this should work for VS.Net 2008 Team Suite RTM.  I've started downloading VS.Net 2008 RTM.  Oh, yeah, just 30 more hours to go :)

vsnet2008downloadfilemanager

Monday, November 26, 2007

VS.Net 2008 Team Suite RTM Download

I've a MSDN Universal Subscription as a result of my company's Volume Licensing Agreement with Microsoft (MVLS).  Since I've been hearing that VS.Net 2008 has finally gone RTM and is available for download to MSDN subscribers, I decided to expend some bandwidth on downloading it.

Unfortunately, I couldn't find it anywhere.    The first link loudly proclaims that VS.Net 2008 is available on MSDN subscriptions.  It also states  - the red underlined line - that "All English Visual Studio 2008 Editions will be available from 'Top Downloads' below". 

But the Top Subscriber Downloads has only the Trial version. 

vsnet2008download

The only VS.Net 2008 available seems to be the professional version.  Number of  people seem to have downloaded it successfully.  No such luck for me :( 

vsnet2008download2

I'm beginning to doubt if MSDN Universal Subscribers are eligible to receive VS.Net 2008 Team Suite or not.

Technorati Tags: , ,

Saturday, November 24, 2007

How to Generate RCW on the fly in your Nant Scripts

Have you ever tried to remember a research you've done couple of years ago and you're desperate to get your hands on the old code?  And the frustration of trying to remember what you did exactly, if you're unable to find or don't have access anymore to the source?

Well, I ran into one today:

Couple of years ago, I had to implement a build process for one of my projects.
One of the modules was a port from VB 6.0 (to VB.Net) and it was using MSXML2!

I wanted to generate the RCW on the fly for MSXML2.  Now, I want the solution to be generic enough to use on any project that uses interop.

I wrote a function:

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

<project>

<script language="C#" prefix="tlb">

    <imports>

        <import namespace="System" />

        <import namespace="System.Runtime.InteropServices" />

    </imports>

 

    <code>

    <![CDATA[

        <!-- Code Goes Here -->

 

    ]]>

 

    </code>

 

</script>

</project>

 

Here's the CDATA Section.  Given here to preserve formatting:

[DllImport("oleaut32.dll", PreserveSig=false)]

private static extern void QueryPathOfRegTypeLib(ref Guid guid, ushort majorVer, ushort minorVer, uint lcid, [MarshalAs(UnmanagedType.BStr)] out string path);

 

[Function("find-path")]

public string GetTypeLibPath(string guid, ushort major, ushort minor, uint lcid)

{

    Guid actualGuid = new Guid(guid);

    string tlbName = null;

 

    try

    {

        QueryPathOfRegTypeLib(ref actualGuid, major, minor, lcid, out tlbName);

    }

    catch (COMException e)

    {

        //Typelib wasn't found - tlbimp will barf

        //when the compile happens, but we won't worry about it.

        Console.WriteLine("[find-path] " + "ERROR!!! " + e.Message);

    }

 

    return tlbName.TrimEnd();

 

}


 

Now, wherever I wanted, I could use it thus:

<!-- Find out location of MSXML2 and create an interop assembly-->

<property name="com.typelib.fullpath"  value="${tlb::find-path('F5078F18-C551-11D3-89B9-0000F81FE221',3,0,0)}"/>

 

<!--

  Somehow the return value from the find-path function contains a character

  at the very end causing <tlbimp> to fail.  Removing the last character from

  the property as a workaround.     

-->

<tlbimp typelib="${string::substring(com.typelib.fullpath,0, string::get-length(com.typelib.fullpath)-1)}"

        output="${source.baseFolder}/Intouch8/bin/MSXML2.dll"

    />


The function I was trying to remember was the API call: QueryPathOfRegTypeLib.
Oooff... (sigh of relief).

Now that I've blogged it, I am sure I will find it next time :)

 

Technorati Tags: , ,

Monday, November 05, 2007

Core Values

I would like to work for a Software company that:

  • Values Technical excellence
  • Believes in being the best at what it does: Producing Quality Software
    • Good design produces a quality product that reduces rework later
    • Believes that software must be designed for change
  • Believes Software Development is fun!  And strives to keep it so.
  • Encourages a product mindset
    • A product mindset is one where even a small project of 3 months duration is developed as though it were a marketable product.
  • Believes fostering trust with the client
  • Emphasizes on automation to keep the process overhead to a minimum
  • Encourages people to learn constantly and rewards them for their knowledge.
  • Maintains a flat hierarchy
  • Emphasizes Agile project management practices

Somehow, I've come to think all other bullets can just be restated with a single sentence:  Agile must be the way of live in my dream company :)

Tuesday, October 23, 2007

Traveling Back Home [with my new Samsung SyncMaster 206 BW 20" LCD]

I'm leaving Sweden tomorrow and will be back in India on 26th October.  Can't wait to hookup my shiny, Samsung SyncMaster 206 BW 20" LCD Monitor :)  I have to see how compatible is my "old" Nvidia GeForce 6200 card.

Wednesday, October 17, 2007

Bake vs. Boobs?

[17th October 2007 15:15PM] Update: Fine... I don't have to build one... It already exists in  the Boo Build System.  I think I need to stop using my blog as a scratch pad of ideas ;)  Still, it would be nice to know if Boobs meets the goals I had in mind:

  • It's full fledged DSL for Build [like Rake.  So very powerful.  I suspect Boo can do stuff that Ruby cannot in terms of extensible syntax. ]
  • It should be able to leverage the tasks already written for Nant [in other .Net languages]
  • Easy to use

Tuesday, October 16, 2007

Bake (?) - A Rake Port in Boo?

I defined a Build Process and wrote the NAnt build scripts [MSBuild wasn't even in its beta then]  for one of the .Net projects I was with quite sometimes ago.  Can you imagine a fortune 500 company's billion dollar Enterprise Web site without a Source Control system or Build system in place?   No way, right?  Wise up guys!

I'll reserve posting about the actual process for later.  Suffice to say that this project found so many issues with VSS 6.0d [which the company was insisting we use it].  And then I had an opportunity work with Perforce and I loved it!

Now, I can actually have track builds with all the changelists they include and mail to individual developers that had checked-in code, in case of a broken build.

Because Rahien is so vocal about DSL and evangelizing Boo, I was thinking of building a DSL that would ease my pain of having to define a Build Process for each of the Source Control / Build System Provider combinations.  

Let me make no bones about it:  While I'm comfortable with the concept of "DSL"s, I'm quite new to the idea of building one.  And I'm new to Boo.  

But the idea of a DSL was so compelling till I found great minds have already been at work ;)  I think it's Paul Graham who said "If you think you have a good idea, chances are that somebody's already working on it" .  Sigh!  Also, My idea of DSL for a Build language has evolved once I've seen how Rake is implemented.

But I guess, it would be a good idea to still implement this [at least just to learn Boo].

One disadvantage of an "internal DSL" as Martin Fowler calls them is ignoring large number of Tasks that Ant/Nant/MSBuild projects have accumulated over time.  If I need a SubVersion checkout task, I may have to reinvent the wheel in my DSL, unless my DSL has a way of integrating this body of work. 

If my DSL is in C# [Well... Rahien says C# is not "suitable" for writing such a DSL.  I choose to believe him as I have a vested interest in learning Boo], I may well be able to leverage all of Nant's tasks.

My vision is [was] to have a single language that would describe the build process   The language would "compile" down to the requirements you have either Ant/Nant/MSBuild scripts with appropriate tasks for Source control provider of your choice.  Since the Build Systems themselves are extendible and have massive community that revolve around them, it seems like a very good idea.  It may be esoterically dumb!  Let me think about it a bit more.

 

[17th October 2007 14:37PM] Update:   OK.  Why to compile it "down" to Nant/MSBuild scripts?  Since Boo is already in .Net fold, we can just use the existing tasks [from NantContrib/ MSBuildContrib?] as is!  No?

Monday, October 15, 2007

350 GB External HDD & Fat32

I ran into an interesting problem over the weekend.  On Saturday, I had bought Elements External Hard Disk Drive, a 350 GB mammoth just to back up some stuff from my laptop.

Aside: Hmm.. backing up for turning your laptop in is no fun.  Hate this part of the consulting business.

When I switched it on and connected to my laptop, it purred happily and identified itself as D:.   First up was the VS.Net 2008 Beta VPC download.    In you go!

It copied first two files [base*.*] and choked on the third one, OrcasBeta2_VSTS.vhd, the eleven GB  virtual hard disk.    The message? 

"You're running out of disk space in drive D:

 Do you want windows to help clean your mess up and free some space?"

Not exactly.  It was close though for a WTF!  Ever had the sinking feeling thinking your newly bought device is just money down the drain?  Fortunately, Google bailed me out - as usual - with this information that also lead me here.

Well, well, it seems that the file format that HDD came with was Fat32.  Surprise, Surprise!  Just ran the convert utility to peace of mind.

 

usbhddntfs

 

Thursday, October 11, 2007

Google, Where are you taking me today?

One of my colleagues asked me why I love Google so much [among millions of others]?  I, in turn, asked him how he uses Google.  He gave me a stare that said, "Are you nuts?  Everyone knows that Google is the best search engine out there!".  I took him to my desk and gave him a crash-course on "Google: How to".  Here's an except from the conversation:

[Note: Bear with me, I'm starting from the very beginning]

  1. Get yourself a Google - Gmail - id
  2. Enable Web History
    • Have you ever felt your browser based bookmarks are inadequate?
    • Have you ever searched for links bookmarked earlier?
    • Have you missed your home PC while at office or vice versa?
      • For the browser history etc. I mean
    • If you have answered 'Yes' any of the above, EWH is for you.
      • Privacy Paranoid:  You can manage your data        [Add/Delete]
      • Also:  You have the option of logging out if you don't want Google to know
        • They know it anyway... but ignorance is bliss.  We'll hope Google is more ethical.
  3. Install Google Toolbar
  4. Google Bookmarks
    • Use bookmarks in Google Toolbar to tag links
      • Multiple tags are allowed.  Use as many as possible for you to be able to find it though multiple avenues [of thought] later. 
    • Carry your Bookmarks everywhere
    • I have one complaint though:  Hierarchical Tagging. 
      • Why can't I have a Tag hierarchy?  It'll will halve my Bookmark menu.
      • Google can infer hierarchy from labels too. 
        • I use labels like: .Net:Security, MS:JavaScript, Agile:Scrum etc.
      • Can't we extend Google Toolbar to implement this?  I digress.
  5.  iGoogle: Customize home page
    • Some of the widgets I use
      • Google Reader
      • Gmail
      • iSuggest [15th Oct '07] Update : Thanks to this post here, I now can convert my iGoogle into Google Suggest
      • TODO
      • Google Bookmarks
      • Wikipedia
      • Search.Net [Google Custom Search!  What the heck!  I'll come to it in a minute]
      • Google Calendar and
      • Dilbert!
  6. Google Notebook
    • Clip HTML from any site [if you have the browser extension]
    • Add your own notes to search results using "Note This" link
  7. Google Search Specials
    • define: SOA
      • Expands Acronyms... SOA ==> Service Oriented Architecture
    • Advanced Search [A full list is out of scope]
      • Site Search
        • site:msdn.microsoft.com filetype:pdf
      • Image Search
        • filetype:gif
      • Use Google as calculator
  8. Google Office(!)
    • Spreadsheets / Documents
      • Online Collaboration
      • Share documents that you and your friend can edit online
    • Calendar
  9. Blogger
    • Create your own blog
    • Blogger does not allow image uploads.  See Picassa
    • You can host your blog in your own domain
  10. Page Creator
    • Create simple HTML Pages
  11. Google Apps
    • Do you own a domain?  Google can host it for you - Free of cost
    • You can create - up to 100 email ids - me@mynewstartup.com
    • You can also create your own pages for your site
      • A word of warning:  You need to disable this if you want to host your blog in the same domain.
  12. Google Photos aka. Picassa
    • You may download Picassa plugin for Windows Live Writer
  13. Google Code
    •  Open Source Code Hosting
    • Note:  You need Subversion to download code
  14. Google Checkout
    • A Service like Paypal [Registered but haven't used yet]
  15. Google Reader
    • It's an online feed [RSS / Atom] Reader
  16. Google Talk
    • You can even talk with friends who have logged into Gmail
      • Client not absolutely a must
    • I use Yahoo! at home most of the time.  Microsoft Messenger & Google Talk at office. 
  17. Google Maps
    • Custom Maps
    • Street View
  18. Google Custom Search
  19. Google Directory
    • Categorized Search  akin to looking up Yellow Pages
  20. Google Suggest
    • I use Google Toolbar, so I do not use the Web version often

Disclaimer:

There are entire books devoted to what you can do with Google. Try amazon.  You can also get a full list of Google offerings here and here.  I have not mentioned Google Gears, Google Desktop or other Google APIs.  I have not mentioned Google Timeline view or Google Shortcuts.

I've only included only what I use  [today] that has transformed my browsing experience.  Give in to the temptation!

Wednesday, October 10, 2007

Color.FromArgb(r, g, b).ToKnownColor()

I was going through the code of CSAH when I came across the class HtmlColor.  It does a mapping of r, g, b colors to a name by doing this:

this.color = String.Format("#{0:x2}{1:x2}{2:x2}", r, g, b);
switch (this.color)
{
    case "#00ffff":
        this.color = "aqua";
        break;
    case "#000000":
        this.color = "black";
        break;
        // more code

 

I tried this:

Enum.GetName(typeof(KnownColor), Color.FromArgb(255, r, g, b).ToKnownColor());

 

Nope.. didn't work!  ToKnownColor() was returning zero.  A quick lookup in MSDN Documentation proved my worst fears.  Unless you create a Color FromName, ToKnownColor() will return zero!

I googled and found this solution.  Here's my improved(?) version:

Dictionary<int, string> colorCache = new Dictionary<int, string>();
public string GetKnownColorName(int r, int g, int b)
{
    int iArgb = Color.FromArgb(r, g, b).ToArgb();
 
    if (this.colorCache.ContainsKey(iArgb)) 
        return this.colorCache[iArgb];
 
    string namedColor = null;
    foreach (string name in Enum.GetNames(typeof(KnownColor)))
    {
        Color kc = Color.FromName(name);
        if (!kc.IsSystemColor && kc.ToArgb() == iArgb)
        {
            namedColor = kc.Name;
            this.colorCache.Add(iArgb, namedColor);
            break;
        }
    }
 
    return namedColor;
}
 
Technorati Tags: ,

Local Storage != Offline?

I'm tinkering with at Dojo Offline Toolkit now.  It seems that Dojo Offline integrates with Google Gears as well.  I didn't suspect "Offline" [or "Offlining"] might be greater than Local Storage.  Dumb me!

Yeah, Dojo 0.9.0 download has GearsStorageProvider & FlashStorageProvider scripts under dojox\storage folder [No SilverlightProvider yet].

Will post my understanding soon as I get my 'aha' :)

 

Aside: Dojo 0.9.0's archive is a *.tar.gz file.  I used UltimateZip Command Line 1.0 to unzip it.

 

Monday, October 08, 2007

Ajax Local Storage and Grinding Google Gears

You're on a proxy server which requires authentication. Please note that we're currently unable to support this type of proxy.

This is the error Google Gears displays because I'm behind a corporate firewall [that requires authentication, naturally].  Considering that it must be trivial for Google to provide this functionality out of the box, its absence is puzzling.

Fiddler2 does it out-of-the-box but then it's not an IE plug-in.  Nikhil's WebDevelopmentHelper does it [it's an IE plug-in] but may not be a "man-in-the-middle".  It may just be listening in on the conversation between IE & the proxy.

So, today, for local storage, you could use:

Hello Microsoft, [knock... knock] are you guys listening?   Here's your chance for one-up-man-ship.  By providing local storage and every other thing everybody has been asking for in Silverlight,  you could still be ahead of Google [Gears]!.   [Aside: Hey, let's not panic,  YouOS  is no reason for us to not improve IE, right? :) ]

  • You can wait for Microsoft to update Silverlight or roll your own IE plug-in.  Easier to do in VB 6.0 than in .Net  [Need no CLR or the Framework].  Write a signed Script-able ActiveX control that could be configured by JavaScript.  Users could also override that info through a Configuration screen.   For example, override the application preference for 100GB of local space [:)] and deny access to his/her webcam etc. etc. [just as in Flash].

Friday, September 28, 2007

Cross domain XHRs and Localhost vs. 127.0.0.1

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

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

crossdomainff

 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 http://www.google.com] and if user clicks 'Yes', it ALLOWS even Cross domain XHRs.

crossdomainff2

 

Technorati Tags: , , ,

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:

scrip#-3

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

/command.aspx?command=GetServerTimestamp&t=1323423432

Here are the results:

scrip#-2

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:

scrip#-1

 

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;
    2 
    3 namespace NewNameSpace
    4 {
    5     public class Reverser
    6     {
    7         public static void Main(string[] args)
    8         {
    9             Console.WriteLine(Reverse(args[0]));
   10         }
   11 
   12         public static string Reverse(string str)
   13         {
   14             char[] chars = str.ToCharArray();
   15             Array.Reverse(chars);
   16             return new string(chars);
   17         }
   18 
   19     }
   20 }

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

reverse

Here's the Javascript generated:

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

 

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:

reverse2

Oops...

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]

vsnetsp-2

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

vsnetsp-1

 

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:

 ifdebug-8

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

 

ifdebug-9

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   }
   10 
   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   }
   24 
   25 #endif
   26     [Conditional("DEBUG")]
   27     public static void Method4()
   28     {
   29     }
   30 
   31 }
   32 
   33 
   34 #if DEBUG 
   35 public class IFDebug2 {
   36 }
   37 
   38 
   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
   53 
   54 [Conditional("DEBUG")]
   55 public class IFDebug4 : Attribute
   56 {
   57     public IFDebug4()
   58     {
   59         IFDebug.Method4();
   60     }
   61 
   62 }
   63 

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:

ifdebug-6

 

What if I do a RELEASE build?

ifdebug-3

 

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 :)

Wednesday, August 29, 2007

Assembly.GetCallingAssembly()

I intend to become a serious tech blogger from now on.
[Oh yeah, it's something we that hold day jobs and family (wife & kid) to boot promise ourselves daily :)] I ran into Assembly.GetCallingAssembly() while working on a larger problem [which again I hope to blog in a series of posts succeeding this one].

  1. Fireup your notepad, copy/paste or type (oh, look out for Tenosynovitis) the below code.
  2. Save as CalledAsm.cs
  3. In VS.Net command prompt compile using, csc /t:library CalledAsm.cs
    1 using System;
    2 using System.Reflection;
    3 using System.Runtime.CompilerServices;
    4 
    5 public class CalledType
    6 {
    7     protected static void InternallyCalledMethod()
    8     {
    9         Console.WriteLine("Called Assembly in InternallyCalledMethod is {0}", Assembly.GetCallingAssembly().FullName);
   10 
   11     }
   12 
   13     public static void CalledMethod()
   14     {
   15         Console.WriteLine("Called Assembly in CalledMethod is {0}", Assembly.GetCallingAssembly().FullName);
   16         InternallyCalledMethod();
   17     }
   18 }
  1. In a new file, type the below code
  2. Save as CallingAsm.cs
  3. Compile using csc /t:exe CallingAsm.cs /r:CalledAsm.dll
    1 public class CallingAsm
    2 {
    3 
    4     public static void Main()
    5     {
    6         CalledType.CalledMethod();
    7     }
    8 }


getexecasm-1


Oops... CallingAsm in CalledMethod() is okay. But even in InternallyCalledMethod()?
The answer is inlining... C# compiler is inlining InternallyCalledMethod!

    1 using System;
    2 using System.Reflection;
    3 using System.Runtime.CompilerServices;
    4 
    5 public class CalledType
    6 {
    7     [MethodImpl(MethodImplOptions.NoInlining)]
    8     protected static void InternallyCalledMethod()
    9     {
   10         Console.WriteLine("Called Assembly in InternallyCalledMethod is {0}", Assembly.GetCallingAssembly().FullName);
   11 
   12     }
   13 
   14     public static void CalledMethod()
   15     {
   16         Console.WriteLine("Called Assembly in CalledMethod is {0}", Assembly.GetCallingAssembly().FullName);
   17         InternallyCalledMethod();
   18     }
   19 }



getexecasm-2

So, I trust GetCallingAssembly() to work only in frontline methods i.e. methods I know that would only be called from a different assembly. For example, a public method on my framework class that I do NOT call internally.

But for this to consistently work, you may need to know when does C# compiler inlines method calls?  Here's what MSDN says:

If the method that calls the GetCallingAssembly method is expanded inline by the compiler (that is, if the compiler inserts the function body into the emitted Microsoft intermediate language (MSIL), rather than emitting a function call), then the assembly returned by the GetCallingAssembly method is the assembly containing the inline code. This might be different from the assembly that contains the original method. To ensure that a method that calls the GetCallingAssembly method is not inlined by the compiler, you can apply the MethodImplAttribute attribute with MethodImplOptions.NoInlining.


Which I infer that inlining may happen across assemblies. So, even though the above code works, I feel safer with:

   14 [MethodImpl(MethodImplOptions.NoInlining)]
   15 public static void CalledMethod()
   16 {
   17     Console.WriteLine("Called Assembly in CalledMethod is {0}", Assembly.GetCallingAssembly().FullName);
   18     InternallyCalledMethod();
   19 }
 
 
Update:  How come my blog suddenly starting to look professional?  Thanks to CSAH

 

Friday, April 13, 2007

Windows Vista Upgrade Advisor & "Failure decoding embedded permission set object"

I downloaded Windows Vista Upgrade Advisor from microsoft.com.

For the record, I have:
1. Windows XP SP2
2. .Net 1.0, 1.1, 2.0, 3.0

When I installed the upgrade advisor, it threw the following error: "Failure decoding embedded permission set object". I googled and came up dry. Finally, I saw the light and modified the VistaUpgradeAdvisor.exe.config file:


    1 <?xml version="1.0" encoding="utf-8"?>
    2 <configuration>
    3   <appSettings>
    4     <add key="ShowDeviceVenderComments" value="true" />
    5     <add key="ShowAppsThatWorks" value="true" />
    6   </appSettings>
    7 
    8   <startup>
    9     <supportedRuntime version="v2.0.50727" />
   10   </startup>
   11 
   12 </configuration>


.Net is supposed to run side-by-side, right? If the UpgradeAdvisor supports 1.1, why did it require the modifications I did? We'll dissect the behavior in my next post.

Thursday, March 15, 2007

Yahoo! I lost my Yahoo ID!

Well... I'm not sure if it is identity theft yet, but I lost my Yahoo! id vyas_b@yahoo.com. I've been using a STRONG password for the past decade but yet one fine morning yahoo refuses to log me on. The password retrieval page asked me for three pieces of information which I was unable to furnish as: 1. I may have given a wrong birthday (when Yahoo allowed you to edit your birthdays). 2. I am based out of India but I wanted my ID to be on Yahoo.com (as Yahoo was making life difficult for everyone and subtly pushing people towards getting a co.in ID). So I might have abbreivated my then current postal code to make it a 5 digit US zip. 3. To cap it all, it was an ID created for me by somebody else. I am still surprised I was using it for as long as I did. Bottomline: 1. I lost my whole bunch of email contacts in my messenger. a. OK. Not entirely true. I was able to retrieve all the Yahoo IDs of my active friends from C:\Program Files\Yahoo!\Messenger\Profiles\vyas_b\Archive\Messages. b. If you're one of them, please let me know by posting here. :) I also Orkut for your information. 2. I lost all my password emails. Now I have to change my passwords for all my other accounts [wherever I had registered on the web for news / purchases etc. etc.]. 3. I lost all my contacts 4. I have to change my primary personal email 5. And I discovered Google Apps for my domain!

Monday, January 08, 2007

New Blogger Woes

I'm trying to post some code after a LONG time! This "new" blogger is frustrating me. I wanted to post some code, which has <script> tags. It wouldn't let me. I downloaded Word Add-in hoping that would resolve the problem (as word automatically encodes HTML content). To no avail! The info that blogger word add-in doesn't work with the new blogger is hidden somewhere that I could find only AFTER I installed and struggled to login for sometime. Now, I'm blogging my woes instead of what I had to! Anyway, welcome back to blogging :)