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.