Thursday, 20 August 2009

A Couple of Issues Discovered While Playing with .NET RIA Services

Installing Windows 7 (which is a breath of fresh air after the nightmare I've had with Vista) and reinstalling all my software on different PCs probably wasn't my best idea given that I had a talk, which needed research, looming. As a result of the best part of a week rebuilding a ton of PCs, I left playing with .NET RIA Services (currently a July 2009 Preview with a 'use at your own risk' 'Go Live' license) much too late (Note to self: You ALWAYS underestimate how long it will take to prep a presentation. Take note!)

The talk, which I gave last night, was An Introduction to PRISM and .NET RIA Services at Vista Squad, which has just renamed itself to "Edge UG" - Die Vista die! ;-) For those who missed it - don't worry - it wasn't one of my best efforts, and although folks were kind about it afterwards and tweeted nice things, the reality is the complexity levels of different sections were too at variance with each other and because I was running out of time I skipped an important initial .NET RIA Services demo which then made the demo I did give confusing as hell, mainly because I skipped about too much (not literally - stop making your own jokes up at the back there!)

Bad preparation aside, when I was researching .NET RIA Services I hit a couple of problems in the most basic demo's almost immediately :-(

The first problem was that the generated proxy code class for Silverlight which the .NET RIA Services produce as part of the Server project build process wasn't being recognised by my Silverlight code that needed to use it. I was getting errors whenever I tried to reference the client-side Proxy classes, or even just add a 'using' statement for the generated class namespace.

After a couple of hours banging my head against a brick wall (this stuff had been working fine on another PC, I just hadn't twigged that the other PC was configured with different software!) I raised a question in the lively .NET RIA Services support forums and thanks to help from Colin Blair discovered the problem was down to my having installed JetBrains Resharper.

It seems that Resharper and .NET RIA Services don't play well together, although in this case I think Resharper is doing what you'd expect it to do (the generated classes aren't included as part of the project and only show up when you click on 'Show hidden files' - so why should Resharper recognise they're there just because some clever hackery is going on within Visual Studio?). There are reports this might be fixed in Resharper version 5 but in the meantime including the file in the project gets you up and running.

Build failure screenshot when Resharper is installed

The other issue I hit was to do with using a System.ComponentModel.DataAnnotations reference to resolve the [Key] attribute required on my POCO properties that I wanted to bind to in my Silverlight-generated class. It turns out that .NET RIA Services installs a newer version of the DataAnnotations class (version 99!) but I was referencing the original 3.5 version. Doh!

DataAnnotations dll version numbers (Add Reference dialog)

Hopefully this blog post will alert others. I found a few folks with the 'cannot resolve Key attribute' DataAnnotations problem when I did a Bing search, but never any responses on what the cause might be. Big thanks to Colin for diagnosing the issues almost immediately.

No comments: