4

For some reason the following code is giving me an exception.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PPCa.Common.Infrastructure;component/Skins/Default.xaml"/>
            <ResourceDictionary>
                <app:ResourceWrapper x:Key="ResourceWrapper" />
                <app:NotOperatorValueConverter x:Key="NotOperatorValueConverter" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>                
</Application.Resources>

Here is the exception:

System.Windows.Markup.XamlParseException occurred
  Message=Failed to assign to property 'System.Windows.ResourceDictionary.Source'. [Line: 11 Position: 44]
  LineNumber=11
  LinePosition=44
  StackTrace:
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
  InnerException: 

Line 11 is this:

<ResourceDictionary Source="/PPCa.Common.Infrastructure;component/Skins/Default.xaml"/>

Am I somehow merging my dictionaries wrongly?

4 Answers 4

9

Why is no one answering my questions? Am I blacklisted or something. People used to help me out quite a bit more. Anyway, I discovered my problem. The exception was a red herring. The problem had nothing to do with my application resource definition. The problem I was having deep inside my resource dictionaries. I was merge-referencing a dictionary inside my dictionary that no longer existed. That was difficult to figure out.

6
  • if no one is answering a question on SO it's because no one knows the answer. The thirst for reputation is quite strong here :)
    – Matt Greer
    Mar 3, 2011 at 15:47
  • So I'm not black listed? I was getting worried. No one was answering any of my questions. Anyway, I figured this one out on my own after a significant amount of time.
    – Jordan
    Mar 3, 2011 at 16:03
  • 3
    SO has an interesting dynamic. it's all reputation driven, and so the type of content that we get here is really influenced by that. Easy questions get the most interest as they are easy rep, hard questions that have generated a lot of interest get good response too. But hard/obscure questions that don't generate much interest tend to go unnoticed. I would say your question here is more in that category than the others.
    – Matt Greer
    Mar 3, 2011 at 17:31
  • This error is on of many XAML parse exceptions that are very obscure. Thank you for saving so much time looking this one up. I went straight to the merge dictionaries and checked for dead resources. fixed.
    – Tri Q Tran
    Sep 14, 2011 at 5:58
  • So basically, a hard question (i.e. one worth an answer for the community) doesn't get an answer as the payment is too low. Perhaps questionners should be able to set the rep award for an answer at the point of posting (other than waiting N days for bounty) Aug 15, 2012 at 13:23
4

Are these dictionaries in the same XAP? If so, a relative path should work. I have used all relative paths to merge in dictionaries without any issue. Here is an example of mine:

<Application.Resources>
    <ResourceDictionary x:Name="appDictionary">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="ControlStylesDictionary" 
                  Source="Resources/Styles/ControlStyles.xaml" />
            <ResourceDictionary x:Name="MenuStylesDictionary" 
                  Source="Resources/Styles/MenuStyles.xaml" />
    </ResourceDictionary>
</Application.Resources>

That is the only difference I can see in your XAML.

1
  • No, my dictionaries are in an external XAP.
    – Jordan
    Mar 3, 2011 at 15:40
3

If the dictionary is in another XAP, you need to download the XAP and load the dictionary from there.

1

I ran into the same problem, same generic error message and found the solution. This appears to be a bug IMHO.

I am building an app for .Net, SL5, WP7.1. To do this I put the code in the .Net app and add source links for the other projects. Works great.

My main app projects are called MyApp.Net, MyApp.SL, and MyApp.WP. However, I make the default namespace and project output for these projects simply MyApp. Again, works great as it should.

I place my resources in projects MyApp.Resources.Net, MyApp.Resources.SL, and MyApp.Resources.WP. There is a bit of a glitch with using the VS source links as Expression Blend wants direct access to the physical files and gets confused when (for example) the MyApp.Resources.WP project contains a source link to a MyStyles.xaml file in the MyApp.Resources.Net projects. Therefore, all my resource projects actually contain physical files. This works fine also, I just have to synch the files manually. No problems so far.

However, for my resource projects I change the namespace and output files to MyApp.Resources. This keeps my application code simple also, regardless the platform it's built for, the namespace is the same.

Yes, I know this is a bit complicated but it allows me to build for 3 platforms (technically 5 if you include Blendability and UnitTesting) all with the same code base.

To continue, if I create a ResourceDictionary as such

<ResourceDictionary Source="/MyApp.Resources;component/Styles/TextStyles.xaml"/>

I get the Failed to assign to property 'System.Windows.ResourceDictionary.Source' etc...

In short, I discovered that if the assembly name contains a '.' this error shows up. For example if I change my project names to simply 'Resources' it works fine. Or if I leave my projects with their default build names of 'MyApp.Resources.WP' it also works fine.

This has nothing to do with changing my resource dll output file names, I change them all day long and it works great, but if they contain a '.' I get the above error. For example, I can change the output name to "MyAppResourceThatWorks" (leaving the project name as MyApp.Resources.WP and load it in App.xaml with

<ResourceDictionary Source="/MyAppResourceThatWorks;component/Styles/TextStyles.xaml"/>

Works great. Change the output name to "MyAppResourcesThatDoNot.Work" and load it with

<ResourceDictionary Source="/MyAppResourceThatDoNot.Work;component/Styles/TextStyles.xaml"/>

Fails.

Yes, I tried changing the assembly properties, etc. etc. It's a load issue with Pack Uri's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.