Consuming resources from external assemblies in Silverlight 4

There’s a bug in Silverlight 4 that prevents you from being able to use resources that are declared in a ResourceDictionary in a referenced assembly.  The error is a XamlParseException whose message is “Failed to assign to property ‘System.Windows.ResourceDictionary.Source’.”.  The problem is that if you have a Silverlight class library whose name ends with “.Resources” it blows up at runtime.  To fix the problem, you must change the assembly name (in the project properties) so that it does not end with “.Resources” but, perhaps, ends with “.Resources.YouHaveToBeKiddingMe“. 😉

Here is an example of using a resource dictionary in an external assembly that will blow up at runtime:

Here is a fixed version:

If you compile a Silverlight application against a project whose assembly’s name ends with “.Resources” that DLL won’t even get included in the XAP or listed in the AppManifest.xml file.  It simply gets ignored, which lead to hours of head-bashing debugging for me.  I hope this workaround saves others the grief!

6 Responses to Consuming resources from external assemblies in Silverlight 4

  1. Graeme says:

    Haha, nice bug… glad to see you aren’t exclusively working on cocoa apps 🙂

  2. Josh Smith says:

    No way, Graeme. WPF/SL is my true love. I’m just flirting with Cocoa at this point. 🙂

  3. Mike Brown says:

    Whoa that is a nasty bug…kinda like learning the hard way that you can’t reference 32Bit libraries from an application compiled to “Any” when running on a 64-bit machine. The error basically implies that the reference library can’t be found. I finally found the problem through some lucky hits on Google, but had spent basically the whole day chasing red herrings.

  4. Josh Smith says:

    Red herrings for sure. I don’t want to recap the nonsense I tried before figuring out this bug. Too painful. Sigh.

  5. Michael Sync says:

    This is a by-design issue since Silverlight 2.. I was naming my loc project like CompanyName.Resource and put a few resx in that project.. and then, got problem..

  6. Rudi Grobler says:

    Tnx Josh… Great post!!!

%d bloggers like this: