Problem with MEF in Windows 8 style apps (Metro)

I noticed when I use NuGet to add MVVMHelpers, the app refuses to start.  I get the following error:

“Unable to activate Windows Store app xxx, The activation request failed with error ‘The app didn’t start’.”

Wow.  Totally unhelpful – even chasing down the event logs didn’t really help much other than to show me a lot of weird errors get logged from Metro apps about tiles!

After experimenting a bit, it turns out the fix is quite simple.  MVVMHelpers relies on MEF for composition and dependency injection.  The MEF package (Microsoft.Composition) which also gets included, adds an app.config with a bunch of assembly binding instructions for version redirection – this is what is causing the failure.  I presume these are for the desktop version of .NET and just don’t work with Windows 8 apps. Here’s what got added to mine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Composition.TypedParts" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.15.0" newVersion="1.0.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Composition.Hosting" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.15.0" newVersion="1.0.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Composition.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.15.0" newVersion="1.0.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Composition.AttributedModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.15.0" newVersion="1.0.15.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>

Remove the app.config to solve the problem. I hope that saves somebody some time and grief! Happy coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s