MIX’11 keynote summary, day 1

It’s time for MIX again! Microsoft’s number one conference for web and phone enthusiasts kicked off in Las Vegas. The first keynote day covered web development, the second one will zero in on phone thingies. Here are the highlights from the first day’s keynotes.

Internet Explorer

imageDean Hachamovitch kicks off the keynote – and he’s wearing a “TEN” T-shirt hinting at IE 10.

  • Examples of real world HTML 5 applications: Foursquare Playground, SVG animation, Director’s Cut (a tool you can use to create custom Bon Jovi music videos), World’s Biggest Pacman, …
    • Lots of boasting on IE 9’s performance, but little else. Still, it’s been a while since a new high-end HTML site recommended a Firefox user to pick up IE 9 (as Foursquare Playground does).
  • IE 9 patterns: A segment of keynote that focused on celebrating IE9’s developer readiness
    • http://html5labs.interoperabilitybridges.com/ – Microsoft’s web site on emerging
    • In the future, platform previews will appear between 8-12 weeks instead of 8 right now; Microsoft feels this will provide more efficient changes and ability to hear the community feedback.
  • Looking forward: IE10 has been developed for three weeks now
    • Improved CSS3 support (visual effects, columns, grid layouts, …). High speed is still a priority, and heavily demoed.
    • Platform Preview 1 is now available for download
    • IE10 demos were run on an ARM machine with 1 GB of memory, demoing the capacity to run (fast) on an ARM machine.
  • PDC 2011 will be held on 13th-16th September in Anaheim, California (the PDC site isn’t up to date yet though).

Developer tooling and server end

Scott Guthrie on the stage, turning the focus back into the server end.

  • Now shipping ASP.NET MVC 3 Tools Updateimage
    • New project templates, including a “use HTML5” switch, NuGet packages pre-installed
    • Entity Framework 4.1 (including code-first capabilities)
    • New jQuery version 1.5 shipping
    • Modernizr – another open source library shipping with Visual Studio through NuGet. This one makes it easier to use HTML5 and still have a working down-level experience.
    • New scaffolding support: Creating a code-first model also creates controllers, views and whatnot.
    • Demo: Creating a simply administrative interface to a podcast. The highlight of the demo was definitely building a code-first model, which then resulted in a generated database, controllers and views, including database constraints and values. Not useful everywhere, but certainly helps in quite a few scenarios.
  • WebMatrix demo: Building a front-end. Demo included buying a web site template from TemplateMonster and using it to whip up a quick web site with WebMatrix, including lots of easy helpers for social features, packge-based helper installation and other stuff.
  • Orchard (an open-source CMS to which Microsoft is contributing code): image
    • Again, returning to WebMatrix, and building a site using Orchard downloaded from the Web Gallery.
    • Version 1.1 now available; the new version is definitely much cleaner than the previous ones.
    • Also heavy demoing of Orchard modules, downloadable and installable pretty much like WordPress plugins. Potential new business opportunity, once all the Microsoft-savvy developers get into WordPress-style development?
  • Windows Azure: Releasing new versions of Access Control Service, Caching and Content Delivery Network, and a feature called Traffic Manager. Not much detail in the keynote though, but look forward to the coming days.
  • Umbraco project founder on stage to discuss the CMS:
    • 10 000 active developers around the world – not bad for an ASP.NET open source project
    • Touting Windows Azure support: Umbraco supports automatic scaling, allowing the admin to specify tolerances. Umbraco will then adjust the number of Azure nodes needed to serve the site properly. Now downloadable: Windows Azure Accelerator for Umbraco

April 12, 2011 · Jouni Heikniemi · One Comment
Tags: , , , , , ,  Â· Posted in: .NET, Web

Out of the dark

It’s been a silent couple of months. Offbeat Solutions has been heads down programming, debugging, optimizing – and then, finally shipping. Now it’s time to look back.

imageIn TechDays Finland 2011 we finally talked about our latest customer project, the www.valio.fi web site (slides available, in Finnish). In case you’re not from around here, Valio is the Finland’s leading company in dairy products and a consumer brand of legendary caliber.

Since the presentation on 31st March, we then finally made the site live on Saturday 2nd April. If you can read Finnish and like food, go check the site out at www.valio.fi!

What’s inside the box?

Essentially we – including our partners in crime, Valve Branding and Appelsiini Finland – delivered an ASP.NET MVC 3 application with quite a few business system integrations and a SQL Server database. Woohoo – that’s not really the exciting part. But we truly did deliver something that’s not the usual user (or developer) experience, so what’s different?

In my opinion, there are six aspects that differentiate the Valio site and the implementation project from most cases developers get sucked into.

  1. User experience. We use modern browser capabilities to make the user experience smoother, faster and visually more appealing. And we do mean so much more than slapping an UpdatePanel here and there.
  2. Platformness. Our task was to implement not just a web site, but also a platform for many future digital marketing endeavors. For this purpose, we expose a whole lot of APIs – and use them ourself.
  3. Automated testing. Although we are nowhere near full test coverage, our test suite compares favorably with most web projects.
  4. Manageabilility. We provide decent tooling to manage the site, reducing the need to type custom SQL queries. Yeah, we have PowerShell commandlets.
  5. Scale. Valio.fi isn’t huge, but it’s running on a cluster of web nodes. It has all the challenges of being on a cluster, most of which never occur on a single-node web site.
  6. Project methodology. We had imperfect Scrum and all, but we had successful teamwork with almost 20 people involved daily – and with relatively few communication issues.

Coming up: More info

Thanks to the openness of Valio and other involved parties, we enjoy pretty broad liberty to discuss the technical specifics of the project. Offbeat Solutions wishes to use this opportunity to disseminate information and best practices on building modern web sites with ASP.net.

During the coming months, we intend to blog on many of the subjects mentioned above. If you have feedback or want to know something about the project, please do leave a comment!

April 8, 2011 · Jouni Heikniemi · 6 Comments
Tags: ,  Â· Posted in: .NET, Web

Finnish municipalities list published in OData!

In an attempt to contribute something back to the community, Offbeat Solutions has published a list of Finnish municipalities, regions, electoral districts and whatnot. And of course, in the modern spirit, using the OData protocol.

Check out the actual material at http://www.offbeat.fi/kunnat.aspx. The description of the data is only available in Finnish, but the data structures themselves are in English – you can also browse yourself just into the OData endpoint.

In case you can read Finnish and are in need of an OData tutorial, there are three new ones available on the ITpro.fi site:

Enjoy!

January 14, 2011 · Jouni Heikniemi · One Comment
Tags:  Â· Posted in: .NET

NullReferenceException from NHibernate in a WCF Service

Don’t you hate it when you get an NullReferenceException? NHibernate 2.1.2 throws one if you have an WCF Service that accesses the NHibernate context. If you get one from NHibernate.Context.WebSessionContext.GetMap(), read on…

It’s really simple but easy to forget – NHibernate’s web session models requires you to have HttpContext available. That particular mentioned method calls HttpContext.Current.Items[…], causing a NullReferenceException when the HttpContext.Current returns null. Quite logical, but since you rarely call WebSessionContext directly, it’s also easy to miss.

The fix is a very straightforward one: Make your service run in ASP.NET Compatibility mode. As described in MSDN article on WCF and ASP.NET coexistence, WCF services have their own processing pipeline, and also have a null HttpContext. However, you can coerce your WCF requests into the ASP.NET Model by enabling compatibility mode. You do this by tagging your service class with an attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyService : DataService<MyDataSource>

Once done, your service should execute fine. However, you might also get an InvalidOperationException with the following message:

The service cannot be activated because it requires ASP.NET compatibility. ASP.NET compatibility is not enabled for this application. Either enable ASP.NET compatibility in web.config or set the AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode property to a value other than Required.

This would indicate a need to add the following to your web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>

Hopefully this will then finally get you back on the track. Smile

December 21, 2010 · Jouni Heikniemi · No Comments
Tags: , ,  Â· Posted in: .NET

Razor + Visual Studio bug: don’t paste whitespace in code

Just a quick note of a bug my wife discovered when working with some Razor code.

If you have ASP.NET MVC 3 Release Candidate installed, you can trigger this. Take a spot where your view file has a C# expression (such as @View.Title), and paste some code after that expression. An example of the code might be “.Trim(' ')”.

Pasting that would have you expect a result of @View.Title.Trim(' '), but instead you end up with @View.Title '').Trim('.

The problem is that pasting a C# segment with whitespace in it causes Visual Studio to mutilate the code strangely. This is particularly apparent when pasting heavy method calls with spaces between arguments. Well, yet another reason to avoid code in your Razor files!

The Razor team confirmed via email that this is a bug in the Release Candidate and will be fixed in RTM.

November 30, 2010 · Jouni Heikniemi · No Comments
Tags:  Â· Posted in: .NET, Web

SANKO meeting on ORM tools, 2010-11-24

Finnish .NET Users Group SANKO will be meeting on 24th November in Leppävaara, Espoo, Finland in order to discuss the concept and details of object-relation mapping. In case you live in the Greater Helsinki Area, check this out!

The agenda is as follows (all sessions in Finnish):

13:00 – 13:15

Welcome & What’s this SANKO? / Jouni Heikniemi

13:15 – 14:00

Introduction to OR mapping: What and why? / Sami Poimala

14:00 – 15:00

Entity Framework 4 / Pasi Taive

15:00 – 15:15

Break

15:15 – 16:00

ORM under the covers – a deep dive on NHibernate / Lauri Kotilainen

16:00 – 17:00

Panel Discussion: Most common problems & the best practices for solving them

 

If you’re interested, register before Monday via the Microsoft site. On behalf of the SANKO team, welcome!

November 19, 2010 · Jouni Heikniemi · No Comments
Tags:  Â· Posted in: .NET

Outputting partial elements with ASP.NET Razor

The new ASP.NET MVC 3 also ships with a totally new option for a view engine, Razor. I’ve now been using Razor in a project for couple of months, and yeah, it’s good – but not entirely without problems. Here I’ll cover one of them.

Imagine a scenario where you’re outputting something that may or may not be a link, depending on the conditions. You’d be tempted to write something like this:

@if(linkUri != null) { <a href='@linkUri'> }
Some text
@if(linkUri != null) { </a> }

… only to find out that it doesn’t work. The error message you’ll be getting is probably “The if block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.” Alternatively, you could get “The foreach block is missing a closing “}”…” or something similar, depending on your enclosing elements.

That’s not really enlightening, and it turns out Razor is smarter than you’d think – and as usual, smart software has a flip side.

You could just balance yourself…

Razor is intended to be written with elements fully enclosed within the C# blocks. Therefore, you might rewrite this as:

@if(linkUri != null) { <a href='@linkUri'>Some text</a> }
else { <text>Some text</text> }

However, such an approach repeats “Some text”, which may be a lengthy expression or even an entire block of HTML, making this rather clumsy. Note that you need the <text>…</text> element to ensure that the else block content gets parsed as HTML instead of C# – the text element will not be present in the resulting HTML, and would be unnecessary if you had any actual tags in there.

Another workaround would be to use the WriteLiteral method and enclose the tags in C# strings, disabling Razor’s parsing logic:

@if(linkUri != null) { WriteLiteral("<a href='" + linkUri + "'>"); }
Some text
@if(linkUri != null) { WriteLiteral("</a>"); }

… but what you really want is @:

Of course, this is a common enough scenario to warrant a syntactic helper. It’s called @:, and it means that the following line is markup, no matter what tags occur. This allows the logic to be written as follows:

@if(linkUri != null) {
  @:<a href='@linkUri'> 

} Some text @if(linkUri != null) { @:</a> }

Unfortunately, as you can see, the @: has a line scope and thus necessitates a few additional line feeds. Despite that, this is rather readable and scales well to complex instances of “Some text”.

Thanks to Andrew Nurse at the Razor team for helping me out with this!

November 17, 2010 · Jouni Heikniemi · One Comment
Tags: ,  Â· Posted in: .NET, Web

Keeping ASP.NET MVC action method argument names separate from the query

ASP.NET MVC does a wonderful job of automatically routing and binding your HTTP request data to the action method. But what if you don’t want to use the same argument names in your routes (for example, query strings) and your methods?

There are a few typical scenarios where you might encounter this.

First, if you’re aiming for absolute shortness in URIs, you’ll end up using querystring arguments like “q”, “aqi” etc. (examples from Google). Such names wouldn’t work well in method names, which have more value in being readable.

Second, if your source code and URIs are in a different language, you might end up with a scenario where you have arguments like ?nimi=5, but not wanting to pollute your code with Finnish, you’d want to translate over to “name” (the same in English).

Third, your query string parameters might have names that are downright uncomfortable to use in programming language of your choice. Typical examples in C# include for, in, class and case. Although you can prefix the names with @ sign to escape the reserved words, it’s a bit clumsy.

BindAttribute to the rescue!

There is actually a very good solution to this: You can specify the name of the field to bind to via an attribute. It’s just a bit confusing: You set the name to a field called “Prefix”, although it is actually the full name of the field. Here you go:

Using BindAttribute
  1. public ActionResult Index
  2.     ([Bind(Prefix = "string")]string text, [Bind(Prefix="integer")]int number)
  3. {
  4.     return Content(text + ", " + number);
  5. }

 

Now you can access this page with an URI like /?string=foo&integer=42, and the resulting output will be “foo, 42”.

November 15, 2010 · Jouni Heikniemi · 4 Comments
Tags:  Â· Posted in: .NET, Web

It takes ten megs to represent three leds

15 years ago we were really struggling with memory problems. Machines typically had 4 megabytes of RAM. And keyboards still had lights for Num lock, Scroll lock and Caps lock. Wait, how are these connected?

imageimageSee, my modern Lenovo W510 has dispensed with the leds on the keyboard (well, we still have one for Caps lock). Good riddance, I didn’t really need them.

But hey! They have been replaced with an on-screen display. When I hit Scroll lock, I get a great visual reminder of the state popping up at the lower-right corner of my screen. And toggling the lock back off, I see yet another grandious display of graphical goodness.

You know, these things come with a cost. Looking at the task manager, I spot these two processes specifically dedicated for this purpose.

image

Looking at this, I realize that those three pesky leds actually take a bit over 2.2 megabytes of memory. And it doesn’t end there. See, both those processes have three threads (hence the “3”), each with a one megabyte stack. Added together with all the other overhead, the nasty indicators slice away almost ten megs of my RAM.

Counting all this together, we are left with the rather stunning conclusion: The leds were replaced with something that consumes twice the typical memory capacity of an early 90s home PC. Oh, and did I mention that the new one is worse, too: The graphical indicator isn’t drawn on top of full-screen applications, nor does it work when a Windows application declares itself “Always on top”.

So much for evolution on this front.

PS. I know the memory calculations are somewhat inaccurate with this little information, but I believe the figures to be sufficiently correct to post this. Feel free to post further details if you bother Process Exploring.

November 10, 2010 · Jouni Heikniemi · 3 Comments
Posted in: General

New guidance: No more Silverlight for the web?

Microsoft sparked quite a controversy when Bob Muglia stated in an ZDnet interview that their “Strategy had changed” regarding Silverlight’s position, and HTML5 was the future way to go. In this post, I look at the whole debacle’s effect on future technology recommendations.

image While this has now been explained by Bob Muglia, Steve Ballmer and Scott Guthrie, all reassuring that Microsoft really views Silverlight as a strategic technology, some things are still left dangling. Of course, none of this was helped by Bing Maps visibly stepping back from Silverlight at the same time.

Of course, everything posted here is my opinion and has nothing to do with Microsoft’s truth.

It’s really XAML vs. HTML, and XAML lives beyond the web

We’ve seen for years that WPF and Silverlight are on a collision course. The two platforms are already reasonably close feature-wise, and the approach seems to be continuing. While full-blown WPF apps will certainly have features beyond Silverlight and Silverlight will have platform qualities unlike the libraryish WPF, these are all really rather insignificant factors. There will be one XAML platform, with one developer competence broadly sufficient for both.

How is this relevant? It is, because XAML has a far broader impact than HTML5. Even with Ray’s Post-PC vision, the full-blown PC is here for at least another ten years. If you want to build a rich UI on one of those still most dominant forms of electronic devices in the world, you will use the XAML stack.

Whether or not the XAML stack will reach devices beyond the desktop PC is a good question. Microsoft Surface is an example of potential direction of expansion, yet Microsoft isn’t exactly poised to conquer the OS market for all slim touch-based household devices. But they have now demonstrated the viability of Silverlight on the Windows Phone 7, so I wouldn’t count them out yet.

HTML 5 was always going to win on the web

Silverlight was an effort to speed up the creation of richer internet application at a time when browser capabilities were not sufficient for application development (certainly because of IE, to an extent). Mind you, it was successful at that: It brought onboard a whole slew of developers previously new to the RIA scene.

An even battle with HTML 5 was never particularly realistic. The W3C process and browser evolution is slow, and Silverlight filled a gap. But just like with CSS, once the spec is actually implementable, the W3C-driven standard is in a position to grab the market, largely because its creation was so heavily driven by vendor consensus.

Given the annoyance towards Flash that had lasted for years, how likely was it ever for another plugin, especially by Microsoft, to replace it?

It is extremely important that Redmondians embrace the HTML5 world. It keeps Microsoft-driven web development relevant – because no, Microsoft won’t control the next generation of device platforms, and yes, we as Microsoft technology developers need to be able to address the wider audience. There’s no way Microsoft would get Silverlight onto all those devices!

The XAML stack still has a role

But even with all the drive HTML 5 has, it doesn’t render everything else obsolete. In fact, the XAML stack has certain great advantages on its side:

  • The developer toolset for WPF/Silverlight is far more mature than for HTML5. Although HTML5 tooling is advancing in leaps, it still consists more of separate libraries compared to the relatively unified developer experience Microsoft provides.
  • The data connectivity between Silverlight and the server is far stronger than it is between HTML5 and a server. Although protocols like OData are becoming more common and JSON serialization is now a part of every respectable programming Framework, a data framework of RIA Services’ caliber and LINQ’s syntax is a luxury HTML5 developers don’t have.
  • Silverlight still has features that beat the HTML5 equivalents. In particular, support for touch, offline mode and various media replay features far exceed what HTML5 has to offer at this time.

When to pick which?

My recommendations:

  • For business apps with need for added richness and web deployment, use Silverlight.
  • For rich “desktop” apps designed for maximum experience on a certain device, of course including Windows Phone 7, use Silverlight.
  • For broad reach consumer apps, default to HTML5.
    • If very high-fidelity media replay or similar features are required, sprinkle islands of Flash or Silverlight into the mix.
    • If your app needs maximum accessibility and search engine visibility, play safe with HTML5.
    • If your app would benefit more from the strong points of the XAML stack as listed above, consider using Silverlight.
  • Gauge the competence of your existing developers. While a Windows Forms business app developer is not ready to just jump into a Silverlight project, the knowledge gap for jumping into an HTML5 endeavor is even wider.
  • With HTML5, developer productivity increases considerably during the next few years. With Silverlight, developer experience is already considerably more mature.

Remember: Although HTML5 is likely to outlive Silverlight, it doesn’t mean Silverlight will die before your application is naturally obsolete. Do balance the short- and long-term benefits for your specific scenario.

November 5, 2010 · Jouni Heikniemi · 3 Comments
Tags: ,  Â· Posted in: .NET, Web