Tuesday, 17 August 2010

Test your websites on all browsers


While writing the last post, about Silverlight disk space on Win XP, I just noticed the difference between IE and Safari on even the most trivial possible website (which I wrote basically as a placeholder for bizspark). Note to self, start testing on IE, umm please.


graphitecharts safari



graphitecharts ie



Silverlight Reports Incorrect Space Usage On Win XP SP2


I opened an old-old version of windows xp (a VM), to test some Silverlight 4 stuff I'm working on (GraphiteCharts). First, the install was flawless, took seconds, damn impressive stuff (I still hate the blue install screen and its hideous font though). While I was at it I thought I'd clean up this VM aka remove unused stuff mostly, when I found that Silverlight reports its space usage incorrectly, or may be the comma actually means a dot (.). This could confuse people who don't know what Silverlight is and think its un-necessarily hogging space. Obligatory screen shot below.


Silverlight CPU Usage



Friday, 13 August 2010

Silverlight 3 and 4 development setup part 2


Following up on the previous post about setting up a silverlight 3 and 4 development environment (link), this post talks about modifying that environment to use visual studio 2010 (ultimate) and expression studio 4 instead of the earlier visual web and c# express editions. There are two parts to setting up, first uninstalling the express versions and the second installing the new studio versions. If you want to go straight to this final development setup without the intermediate express installs then follow steps 1,2,3 and 4 from the previous post; ignore the un-install steps in this one and jump straight to the installation bits.

Un-installs
-----------

1) Uninstall the Silverlight 4 tools for Visual Studio 2010.
2) Uninstall the Silverlight 4 SDK.
3) Uninstall Silverlight 4.
4) Uninstall WCF RIA Services V1.0 for Visual Studio 2010.
WCF RIA services have a nasty-nasty bug and need some registry fixing to get rid off. First uninstall (via Add Remove Programs or Programs and Features in Win7) this will get rid of the folder in MicrosoftSDKs (C:\Program Files\Microsoft SDKs\RIA Services). If however you now close and re-open Programs and Features you'll find WCF RIA services are back, this is because the registry entries have not been removed. You need to go in and manually do this (regedit.exe is your friend). The keys to remove are mentioned here; look for modestyZ's second post, the 4th post overall.
5) Uninstall Visual Web Developer Express 2010.
6) Uninstall Visual C# Express 2010.

Installs
--------

1) Install Visual Studio 2010 (I have Ultimate; thanks to bizspark; but other versions should work as well).
2) Install Silverlight 4 tools for Visual Studio 2010.
3) Install the Silverlight 4 update (mentioned in the previous post), discussed here and available here.
4) Install Expression Studio 4.

That's it [sic], you should now have a working top of the line Silverlight 3 and 4 development environment with support for Visual Studio 2008, 2010 and Expression Studio.

Sunday, 6 June 2010

Silverlight 3 and 4 development setup


This post is more a instruction list for myself than anything else. Microsoft keeps changing the instructions on silverlight.net and it gets harder each time to find the steps needed to setup a working silverlight 3 and 4 development environment. This is how I setup mine. These steps give you a silverlight 3 and 4 development enviroment with Visual Studio 2008 and Visual Web Developer Express 2010. I do not yet have license for Visual Studio 2010 and am thus using the free versions. If everything goes to plan, this setup will give you the ability to develop for Silverlight 3 with VS2008 and both silverlight 3 and 4 with VWD2010.

The steps:
1) Install Visual Studio 2008.
2) Install Visual Studio 2008 SP1 (service pack).
3) Install Silverlight 3 tools. This installs, the Silverlight 3 SDK, Silverlight 3 and tools for Visual Studio 2008. This can be found here.
4) We need to now install an update for the Silverlight 3 SDK as described here. We basically need to un-install build 3.0.40624 of the Silverlight 3 SDK and install the updated 3.0.40818 version available here.
5) Install Visual Studio Web Developer Express 2010. Optionally install Visual C# Express 2010.
6) Now install the Silverlight 4 tools, available here.

Thats it this is all I do for my development environment. I'll write a new post when I get VS2010 and the Expression Suite and update my environment.

Update:
7) An update for the runtime is available, as described here. The direct link to the developer version for Windows is available here.

Sunday, 7 March 2010

Force quitting Visual Studio 2008


Visual Studio 2008 works almost flawlessly, its rock steady and a pleasure to develop with. However, once in a while it has its moment. One such moment (which is not entirely its fault) is when Visual Studio hangs when debugging Silverlight code. This has only happened to me when using Chrome as my default browser, as its out of process plug-in model introduces complications (aka Chrome is hell bent of killing the Silverlight plugin while you troll through your source code trying to find bugs).

Anyway, if you open Windows Task Manager in Windows 7 and select Visual Studio under the applications tab and click the End Task button nothing happens. Visual Studio is still stuck and refuses to die. The way to kill it (or so I think) is to right click the Visual Studio Task (under applications) and select Go To Process. Right click this process name and select End Process Tree to actually kill Visual Studio. You might lose some data in the process, but what the hell atleast the damn thing will die. Next time you start Visual Studio select Internet Explorer as your default browser for awesome trouble free Silverlight debugging.


task manager



Saturday, 6 March 2010

Random Silverlight Exception: System.TypeInitializationException


I was stuck with a Silverlight exception in my code base for almost 2 days. I had no idea what was wrong, let alone get down to fixing it. Fervent googling did not yield desired results either. I did eventually fix it, in fact it was trivial, the problem however is the fact that Visual Studio 2008 gives the most retarded messages, especially when your bug lies at the point where xaml and code meet.
The exception that turns up is
System.TypeInitializationException: The type initializer for '_insert_your_type_here' threw an exception ---> System.ArgumentException: Default value type does not match type of property. 

All it turned out to be was a ‘double’ and ‘int’ mis-match in my case, i.e. the default value used to initialize a dependency property did not match the type the dependency property was initialized to be off. I group my constants in one place in a separate class so that a change in one place is reflected across the application aka no magic values. I had made a mistake by making my default declaration of double type and the dependency property of integer type, hence the error. Here are the code snippets in question.
Constant:
internal static readonly double Divisions = 0;

Dependency property:
        public int Divisions
{
get { return (int)GetValue(DivisionsProperty); }
set { SetValue(DivisionsProperty, value); }
}
public static readonly DependencyProperty DivisionsProperty =
DependencyProperty.Register("Divisions", typeof(int), typeof(Axis),
new PropertyMetadata(DefaultAxisProperties.Divisions, new PropertyChangedCallback(OnDivisionsChanged)));

private static void OnDivisionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((Axis)d).OnDivisionsChanged(e);
}

protected virtual void OnDivisionsChanged(DependencyPropertyChangedEventArgs e)
{
}



I eventually fixed this with the help of svn diff, comparing the last working version of the class with the current one. Instead of ploughing through 4-5000 lines of code and about 500 lines of xaml, the diff reduced it too a few small hot spots that had changed between the versions, and made eventually spotting this bug possible.

Maybe the exception makes it obvious what was wrong, it wasn’t the case for me though, maybe it was just one of those things you get stuck with.

iSight camera on a 21.5 iMac running Windows 7


There is no photobooth type software that  comes with Windows 7. So I went on a download and trial spree of some of the software I found mentioned on forums etc. One of them locked my iSight camera and it stopped working on my main applications, most importantly Skype. A look at the Apple support docs suggested it might be an issue isolated to only my user account. This wasn’t the case and the problem remained in not only all Windows 7 accounts but also the ones on Mac OS X.

I tried to repair my boot camp drivers at first, but soon realized that won’t fix it for the simple reason that the problem exists on the OS X side of things as well, which bootcamp can do nothing about. The way to solve this was pretty simple, just shutdown the system! I was earlier only restarting and jumping between windows and mac os. Simply restarting does not make it work. If after shutting down the camera functionality does not come up you can try a SMC reset.

Friday, 19 February 2010

Tuning Windows 7 performance on VMWare Fusion


VMWare fusion runs great out of the box. It can however be made better, much better. The specific thing I'm going after here is the idle time cpu usage, which my default is around 12 - 14% on my 21.5" iMac. On a friends macbook, I once tuned an XP VM similarly to take its idle time cpu usage down to about 2 - 3%, sometimes lower. Out of the box Parallels for mac has an idle cpu time of around 2 - 3% and much lower memory usage, so I haven't really spent any time tuning it.

The main idea behind tuning performance is to reduce the unnecessary things that the operating system is doing all the time. You can selectively use these methods and others (just google for many more) depending on what you use and not, and can thus not turn off.

The first thing you can do is turn of aero. Use the Windows Classic or Windows 7 Basic themes for reduced window manager overhead. The window managers on both OS X and Windows 7 are directly affected, if you monitor your cpu usage, these processes are WindowServer and dwm.exe for OS X and Windows 7 respectively. Even though dwm.exe has been greatly improved over the Windows 7 RCs, removing aero can make a big difference especially when using the unity mode, which is what I use. More about the window manager can be found here in this stunning talk by the man himself, link .

You can further tweak the Windows 7 Basic or Windows Classic themes to turn off more effects and further improve performance. These settings can be found in Control Panel -> System -> Advanced system settings -> Advanced (tab) -> Settings (under Performance). I don't personally do this.

We'll go after automatic restore points now. I use my virtual machine only for development and do not really care about this particular feature, my code is always backed up in svn dumps both outside and inside the vm. If I do lose my vm for whatever reason, I can simply create a new one its not hard at all and between installing windows 7 and visual studio takes about 2 hours. This article clearly explains how to go about disabling system restore, link .

Next one can disable Indexing to reduce I/O activity or at least limit it. I turn off indexing all together for User accounts and only let it be on for the Start menu. The settings for the same can be found here, Control Panel -> Indexing Options.

I have my virtual machine set to use 1 GB of ram and 1 processor, with an expanding 80 GB hard disk. While the best thing to do would be to allocate all space for the virtual machine upfront, I do not have enough space for that. The reasoning is that expanding and shrinking drives increase cpu usage. This is most likely to happen if your vm starts swapping. A way around this is to add another hard disk to the virtual machine (I prefer the SCSI type) and make this a fixed size 3 GB disk and assign it to the system as swap. After you have made your disk, in Virtual Machine -> Settings -> Hard Disks (make sure pre-allocate disk space is selected, and split into 2 GB files is off), format this to use ntfs with the disk manager by right clicking the volume (Control Panel -> Administrative Tools -> Computer Management -> Disk Management (under storage) ). Again in Control Panel -> System -> Advanced System Settings -> Advanced Tab -> Settings under Performance -> (again) Advanced Tab -> Change under Virtual memory. Uncheck automatically manage paging file size. With C: drive highlighted select No paging file and press the Set button. With the new 3GB drive selected (E: in my case) select Custom size and write 3000 in both the initial and maximum sizes (this prevents unnecessary growth overhead), again press the Set button.

Thats about all I do, if you do try them especially the swap file one don't blame me if things go wrong; for real. For me though these changes bring down vmware's cpu usage to about 2% when idle, below is a screen shot to prove it.


CPU Usage



Tuesday, 16 February 2010

Attention to detail


Apple is known for its attention to detail (at least in their key applications, the ones that are the focus of the PR machine), for eg: in the timer on an iPod or iPhone try setting the time to 00:00 it silently moves to 00:01. There are numerous other little things you spot here and there when using Apple products and software. I have been using Windows 7 for a while now (as a VM), and I quite like it. I spotted one such thing in Windows 7 today and it really made me smile. Its nice when these little hidden additions make your work a little easier. I was copying a backup dump to my installation when one of my cats managed to dis-lodge the usb cable. Rather than spit out an error of doom, Windows 7 spit out an error with a little button at the bottom which said "Try again". Sure enough I re-connected the disk and the file copy resumed. Awesome.