If you tried the Win8 Developer Preview and built WinRT components (native or managed) you noticed the .winmd files. The name stands for Windows Meta Data and the format of these files is the same used by the .NET framework for the CLI, i.e. ECMA-335. That means you can actually read these files with a tool such as ILDASM or Reflector, or of course, through .NET Reflection.
If you look in C:\Windows\System32\WinMetadata folder you’ll find the WinMD files for the Windows Runtime. You can browse the content of these files with one of the aforementioned disassemblers.
Here are two dummy WinRT components, one developed in C++/CX and one in C#.
Native WinRT component in C++/CX | Managed WinRT component in C# |
namespace WinRTNativeComponent { public ref class MyWinRTComponent sealed { int _id; String^ _name; public: MyWinRTComponent () {} ~MyWinRTComponent () {} property int Id { int get() { return _id; } void set(int value) { _id = value; } } property String^ Name { String^ get() {return _name;} void set(String^ value) { _name= value; } } bool Update(int id, String^ name) { { if(_id == id) { _name = name; return true; } return false; } } }; } |
namespace WinRTManagedComponent { public sealed class MyWinRTComponent { public int Id { get; set; } public string Name { get; set; } bool Update(int id, string name) { if (Id == id) { Name = name; return true; } return false; } } } |
In the case of the native component, the output includes a DLL and a WINMD file (and of course a PDB file). In the case of the managed component, the output is either a DLL only or a WINMD only (plus the associated PDB file), depending on the Output type as defined in the project properties. If the type is Class Library the output is a DLL; this is enough if your component is supposed to be consumed from a managed language. However, if the component should be consumed from C++/CX or Javascript, then the project type must be set to WinMD File. In this case the DLL is replaced by a WinMD file, that contains, at least in the current version, both the matadata (as implied by the name) and the implementation.
Native WinRT component in C++/CX | Managed WinRT component in C# |
![]() |
![]() |
It should be possible to use reflection with winmd files. However, the reflection capabilities of .NET 4.5 in this developer preview seem to be very limited. The only available Load method in the Assembly class is
public static Assembly Load(AssemblyName assemblyRef);
Trying to load the winmd file fails with a FailLoadException with the message “Could not load file or assembly ‘Winmdreflection, ContentType=WindowsRuntime’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0×80131515)”.
try { var assembly = Assembly.Load( new AssemblyName() { Name = "WinRTManagedComponent", ContentType = AssemblyContentType.WindowsRuntime }); } catch (Exception ex) { }
It is possible though to read information for the types described in an winmd file in native code using the IMetaDataImport/IMetaDataImport2 COM interfaces. You can find an example here. But this has the drawback that you have to instantiate an object first and then query for its type information.
To use a Windows Runtime component in a Metro application (managed or native) you have to add a reference to it. That is pretty straight forward. In the following example I’m adding a reference in a C++ Metro application to the two WinRT components, one native and one managed, shown earlier. To do this, you can go to the project’s property page and open the Common Properties > Frameworks and References page, or use the References command from the project’s context menu which opens that page directly. You can add a reference to a project from the same solution, to a Windows component or you can browse for the winmd file.
Having done that you can instantiate the WinRT components.
auto obj1 = ref new WinRTManagedComponent::MyWinRTComponent(); obj1->Id = 1; obj1->Name = L"marius"; auto obj2 = ref new WinRTNativeComponent::MyWinRTComponent(); obj2->Id = 1; obj2->Name = L"marius";