Wednesday 21 April 2010

Microsoft's Free Silverlight 4 LOB Training Course (and dealing with possible Database Issues)

I'm often asked for advice on how best to learn Silverlight, and with the release of Silverlight 4 last week folks are keener than ever to get to grips with the technology, particularly for writing line-of-business applications.


At the time of writing, the only book available for Silverlight 4 is Microsoft Silverlight 4 Business Application Development. Although the book advertises itself as a 'Beginner's Guide', and has been written and technically edited by folks boasting the usual expert 'MVP' and 'Insider' credentials, I would NOT recommend this book for beginners, despite the pedigree of the authors and the basic step-by-step and subsequent analysis structure which I like. The book went to print before Silverlight 4 had RTM'ed, and contains a number of, frankly, quite basic errors that will only confuse those new to Silverlight. These include claims (and screenshots) implying that Visual Studio 2008 can be used to build Silverlight 4 applications, that Blend 3 is a 'required tool' for Silverlight 4 development (Blend 3 does not support Silverlight 4), and a confusing set of step-by-step exercises where the authors and reviewers don't seem to have realised that when working with font sizes Blend 4 (which has to be used for Silverlight 4) works with point sizes which are different from the underlying Silverlight XAML pixel sizes), or that if you put a TargetType of UserControl on a resource style Blend isn't going to then let you use that same style on a button!


Microsoft are obviously aware of the 'learning curve' problem with Silverlight 4 and have launched a free Silverlight 4 training course. The course includes 8 modules around 'Building Silverlight 4 Business Applications' which they estimate comprises 2 days worth of training, and has been written and presented (it includes videos as well as step-by-step follow along exercises) by Ian Griffiths, who has an excellent reputation as a Silverlight and WPF trainer (his Silverlight 3 'on demand' training course for Pluralsight looks very good indeed, from what I saw of it, and apparently a Silverlight 4 version of that 'soup to nuts' material is on its way if you sign up for Pluralsight training).


Ian and Microsoft are keen to point out that the free training course that's been provided through Microsoft's Channel 9 outlet is NOT a 'soup to nuts' Silverlight training course, and that there are assumptions you've done at least some of the 'Getting Started' Silverlight tutorials available at the Microsoft site. However the course does introduce the MVVM pattern, make good use of WCF RIA Services and in its last module even introduces MEF - all stuff that typically gets missed out from basic Silverlight training. Last night I decided to give it a quick look.

Unfortunately I hit problems almost immediately because of the configuration of my local machine, and so the main purpose of this blog entry is to document how to fix these problems for those who may find themselves hitting the same issues.


I do still have one outstanding problem in that Visual Studio 2010 never seems to 'remember' the changes I've made to the database connection string, and requires me to make the same modifications every time I restart it. To me this looks like a bug (I've made the mods and happily run new builds that work - why is Visual Studio 2010 ignoring them on restart?) but if anyone knows different I'd appreciate a reply in the Comments section of this blog post.


Very early on in the first hands on lab (actually Module 2, since Module 1 comprises a simple video introduction to the course and nothing more) you are asked to add an .mdf database file to your project. When I attempted to view this database using Server Explorer a nasty, and somewhat confusing error dialog appeared, implying that the database file was too 'new' for my installed software (SQL Server 2008 with all the latest service packs and updates applied):

Error message when SQL Server 2008 Express isn't installed


It turns out that his message is the result of the database file being opened with SQL Server 2005 Express edition, when it is a SQL Server 2008 Express edition database. Although I'd updated my machine with an installation of SQL Server 2008 some time ago, and then installed Visual Studio 2010 I'd never installed SQL Server 2008 Express Edition.


The fix appeared relatively straightforward: change the connection string to use the installed version of SQL Server 2008 rather than the version of SQL Server 2005 Express Edition it seemed to have decided was the preferred option. This is achieved using the 'Modify Connection' context menu option in the server explorer:
The 'Modify Connection' context menu option


The resulting dialog box has an Advanced properties tab which you display by clicking on the Advanced button:
Dialog giving access to the Advanced properties


From here it's a simple matter of selecting the appropriate SQL Server instance from the drop-down list box. The dropdown list box initially shows the SQL Server 2005 Express instance it has decided to use:
SQL Server instance has been set to SQL Server 2005 Express


It's a simple matter to change it to the SQL Server 2008 instance:
SQL Server instance reset to SQL Server 2008


However this then introduces a new error when 'OK' or 'Test Connection' is selected, as shown below:
User authentication flag error when using full version of SQL Server 2008


It seems there are some ASP.NET user authentication security precautions with the developer/full versions of SQL Server 2008 that aren't there with the SQL Server 2008 Express edition, causing this error to be displayed. The only solution to the problem appears to be to install SQL Server 2008 Express edition as well as the full edition already installed. Make sure you download the Sp1 version of the Express edition (which can be found here to avoid warnings about an out-of-date incompatible version) and be prepared for a restart before the install will fully run.


Once you've installed the Express Edition you can change the connection string, as shown previously, to point to the newly installed Express instance, and happily proceed with what looks to be a fun training course.

Setting the connection string to the newly installed SQL Server 2008 Express instance


Now when you click on the 'Test Connection' button the errors have all gone away:
Finally - a good connection (until you restart Visual Studio 2010)


As indicated earlier, the only problem is that every time you restart Visual Studio 2010 the database connection string seems to reset itself to the SQL Server 2005 Express instance, causing the initial 'version' error that kicked off this whole blog entry.


If anyone knows how to make this error go away for good I'd be happy to hear from you (and will update this blog entry accordingly).

Monday 19 April 2010

Visual Studio 2010 Hanging On Splash Screen (Add-in problems)

Last week, in the middle of a manic week of Microsoft TechDays Visual Studio 2010 finally got released to manufacturing (RTM'ed) and being conveniently 'between contracts' with no client software dependencies needed on my main PC, it seemed a good time to install it.


I hit a problem just after I installed the Silverlight Tools for Visual Studio 2010 which went to 'Release Candidate 2' status just a few days later. Visual Studio 2010 would 'hang' on the splash screen. Task Manager showed no sign of Visual Studio on the Application tab but the Processes tab showed devenv.exe stuck at 50% CPU and nothing would happen until I killed the process.


A quick search on 'Bingle' (;-)) showed several reports of others having a similar problem - but only with earlier versions of Visual Studio, and none of the causes seemed relevant to my particular situation. I suspected that something about the Silverlight Tools installation had gone wrong.


In the event it was not the Silverlight Tools that were the source of my problems, but the combination of a couple of third party add-ins.


Three Visual Studio add-ins I use are JetBrains Resharper, Red Gate Reflector Pro and NDepend 3. All are excellent tools that worked fine in Visual Studio 2008 and which I've come to rely on when writing my code. In different ways they all help me write better quality code and whenever one of them isn't available I tend to miss it.


Removing the add-ins one by one it initially appeared that Red Gate Reflector Pro was the cause of the problem, so I removed the add-in, raised a support call and was able to work pretty much as normal.


Red Gate responded very quickly to my support call. 'Was I by any chance using NDepend?' they asked. Well yes, I was. 'Have you got the latest version? There was a point release update to NDepend 3 which fixed a co-existence problem'. A quick test, removing NDepend and then adding back Red Gate Reflector Pro proved that it was actually running the two add-ins together that was the cause of my frozen splash screen.


I hadn't updated my copy of NDepend 3 since it had first been released. There is a message box on the visual panel that indicates if you are using the latest version or not, and this was indicating that I was on the latest version. Of course it turned out that this was an early bug - one fixed in a later release, but one which I hadn't downloaded because I wasn't aware of it.


Sure enough, downloading the latest release (from 15th April) fixed all the problems and I'm now able to use all my add-ins with Visual Studio 2010 which I'm loving (apart from the very slow start-up time which seems much worse than Visual Studio 2008).


Although the experience was initially disconcerting I must say I was very impressed with the swift responses from the producers of those third party add-ins. A couple of tweets about the problems and Stephen from Red Gate and Patric from NDepend were immediately in touch. That their products are working, and working well, with the latest version of a complex, largely rewritten, IDE on the day it finally released is pretty impressive by any standard. Well done to both!


I still have one problem with Visual Studio 2010 add-ins. JetBrains Resharper 5 flags false errors in even the most basic XAML. This is a step backwards from the 4.5 release in my view, but the portents for the problems being fixed are good - the company contacted me on a Sunday after I tweeted about how the new release seemed to be a step backwards for Silverlight developers, and Support officially contacted me first thing Monday morning. I'm optimistic they'll fix the issues I've reported (they've already fixed a problem with their web site which I reported at the same time) on a timely basis.


If only vendors in walks of life other than Visual Studio add-in tools were so speedy and pro-active when it came to offering their customers support. The world would be a much more stress-free place!