22

I have a merged resource dictionary in App.xaml Main assembly, which combines various resource dictionaries from separate assemblies: Common and PresentationLayer.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Common;component/Themes/Button.xaml"/>
            <ResourceDictionary Source="/PresentationLayer;component/DataTemplates/AppointmentsDataTemplates.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

At run time the styles in the resource dictionaries are applied to the controls correctly. However, at design time the styles are not applied and Visual Studio 2012 keeps giving the following error:

An error occurred while finding the resource dictionary "/Common;component/Themes/Button.xaml".

And warning:

The resource "BannerButton" could not be resolved.

I came across this post but the problem persists despite Build Action set to Resource. Also, I did not have this problem when running under Visual Studio 2010 or Expression Blend 4. The Main assembly definitely holds a reference to the Common assembly and I haven't changed the Pack URIs.

Community
  • 1
  • 1
Blake Mumford
  • 17,201
  • 12
  • 49
  • 67
  • have you tried using normal relative path? – D J Jan 18 '13 at 05:42
  • @DJ Normal relative path (where the resource dictionary is in Main assembly) works fine. – Blake Mumford Jan 18 '13 at 06:01
  • @DJ Actually, Visual Studio no longer complains of errors, but the designer still does not apply the styles. – Blake Mumford Jan 18 '13 at 06:05
  • yes because the path you are giving is based on component. Even if you resolve this problem your VS will not be able to show designer everytime. Actually you should use Expression Blend or kaxaml tools for designer. VS is bit painfull in these things – D J Jan 18 '13 at 06:28
  • I was getting the same error with: `Source="/MyApp;components/bar.xml"` and then realized I had typos: it's `component` (singular) and `bar.xaml` (XAML, not XML). Ultimately this worked with build action set to either `Resource` or `Page` -- ["Page" is just a binary resource](http://stackoverflow.com/a/145769/1174169) -- and with source as any of: `pack://application:,,,/MyApp;component/bar.xaml`, `/PushToTalk;component/bar.xaml`, `/bar.xaml`, or just plain-ole `bar.xaml`. I'm using VS 2012 Update 4. – cod3monk3y Jul 29 '14 at 16:42
  • I got this same "error" after closing and later reopening a project in Blend 2017 Community. Building the project again made it go away. Honestly, these products certainly seem fragile at times. – Stevens Miller May 31 '17 at 18:39
  • Of what types are your assemblies? Class library project? Shared Project? – Starwave Oct 16 '21 at 18:36

6 Answers6

12

For VS2017 if assembly is referenced and double-checked that all namings are OK try to close VS and delete .vs directory in solution directory. This will cause you to lose all user settings (startup project, WPF designer zoom, etc.) but will fix this.

rattler
  • 379
  • 2
  • 5
  • 15
  • 2
    unfortunately, this is still relevant for VS 2019 (16.4.2) and you saved me from erratic and upsetting errors occurring since a few days... – Yet Another Code Maker Jan 09 '20 at 08:14
  • Still relevant as of Version 16.8.3. I got the annoying error message and the light-blue undersquiggle would not go away. Closing and reopening the solution resolved the problem. – John Alley Dec 31 '20 at 12:52
  • Yes, this sometimes is still needed. Thanks for the suggestions. Good idea. As with rebooting, it is somewhat disappointing that it is still needed, however. – JosephDoggie Aug 30 '22 at 20:15
8

This was a known issue with Visual Studio 2012. See this link at Microsoft Connect. After installing VS2012 Update 1 this issue resolved for me. If you think you're running the most up to date version of VS2012 and still experiencing this issue, make absolutely sure that the update has been applied. I thought I had updated using Windows Update, but then found that I had to tell VS2012 to apply the update. After VS2012 did its thing everything was fine.

Blake Mumford
  • 17,201
  • 12
  • 49
  • 67
  • 2
    I mismatched the version of .NET between the assembly and the project (.NET 4 client profile and .NET non client). Once put both on the same version, problem disappeared, as described in the link provided by Andagavar as 'Alternate Solution'. – MDaldoss Jul 10 '13 at 13:18
4

If you are using Visual Studio 2017, try to restart your computer. The problem may be solved.

Casper
  • 4,435
  • 10
  • 41
  • 72
  • 1
    Visual Studio 2019 ( up to at least Version 16.8.3) the problem resolved for me after I closed and reopened the solution. – John Alley Dec 31 '20 at 12:50
  • This sometimes works, and thanks for the suggestion. It is somewhat disappointing that it is needed, however. – JosephDoggie Aug 30 '22 at 20:14
3

I'm using VS2019 getting this error.

I just restart the VS and the error disappeared.

Even Wonder
  • 1,127
  • 1
  • 14
  • 16
1

Try the same in Window.Resources, make sure you added namespace when using app.xaml and don't forget to change the build option to page where you need to use that app.xaml.

1

I had the same Issue and the cause was wrong spelled word in the resource dictionary xaml file. Check the resource dictionary xaml file for wrong spellings and errors. After correcting the spelling it worked.

Stefan27
  • 845
  • 8
  • 19