WinRT and C#/.NET Components

3/25/2012 By Marco Kesseler 0 comments

WinRT-edition-PDF-Rasterizer.png

Monday morning started with the following question in the sales inbox:

“Do you plan to support Windows 8 Metro Style App’s using the WinRT API’s with a product like PDFRasterizer.NET? If so, when? We are in development now, so would you have a preview version that we could use during development?”

This was the first request after Microsoft announced WinRT during their Build conference in Anaheim CA, September 2011. I googled around trying to quickly understand the implications of providing WinRT editions.Here are my first quick findings (in random order).

#1: WinRT includes the .NET framework.

So we do not have to port our C# code. Good thing! The included framework is .NET 4.5. To target this version we need Visual Studio .NET 2011. Caveat: VS 2011 only runs on Windows 8.

#2: WinRT introduces a new file type: .winmd

We can decide to either output a single .winmd including both API description and implementation. This is required to support non-managed languages such as JavaScript and C++. Or you can ship a pair of files: a DLL containing the implementation plus a .winmd containing the API description only. If you do this, only managed clients can use your component. Since it seems trivial to output a single .winmd (it is a project setting), I do not see a reason to restrict ourselves to managed clients only.

#3: All public classes must be sealed

We definitely don’t want this restriction to propagate to non-WinRT editions. We already have too much #if constructs cluttering our code so I prefer to post-process our normal assemblies to achieve this. We use DeepSea Obfuscator to obfuscate our assemblies. In fact we use it for much more such as changing accessiblity and injecting module assemblies. Fortunately, DeepSea supports sealing classes in a compiled assembly. In fact it also consumes .winmd files.
Looks like adding WinRT editions to our releases should be painless. In the next days we will do some experiments and build a small Metro app that renders PDF documents.