An error occurred while finding the resource dictionary - wpf

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.

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.

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.

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

I'm using VS2019 getting this error.
I just restart the VS and the error disappeared.

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.

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.

Related

WPF Resource is not found by ReSharper in design time but solution builds

I use ReSharper 8.2.3 Full Edition with Visual Studio Ultimate 2013 and .NET 4.5.
The background is that I have a C# WPF solution with a large number of projects. To simplify the description here, I have the following projects:
Project 1: Library with UI resources (styles, fonts etc), including a resource dictionary named ResourceLibrary.xaml.
Project 2: Main exe with some WPF user controls/views and an app.xaml. The WPF user controls do NOT refer directly to ResourceLibrary.xaml in project 1. The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).
Project 3: Library with some WPF user controls/views. All these user controls refer to ResourceLibrary.xaml:
<UserControl.Resources>
<ResourceDictionary Source="/<my_resource_namespace>;component/ResourceLibrary.xaml" />
</UserControl.Resources>
The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).
The solution builds fine, IntelliSense works (finds the static resources in ResourceLibrary.xaml) and ReSharper does not generate any warnings.
However, if the above lines are removed, IntelliSense does not work and ReSharper generates the warning "Resource XXX is not found". Note that this is NOT the case with the XAML files in project 2 that also uses resources in the resource library. The solution builds fine.
I want to avoid to include the resource library in every XAML file due to performance reasons but I do want ReSharper to give me relevant warnings. Is there a workaround to this problem?
I know I can turn the "The resource XXX is not found" warnings off in the ReSharper, but that would prevent me from detecting real resource problems.
You might have solved this already, but this is the solution I used for my own project.
If you add a new WPF User Control in Project 3, change it to Application (and in the code behind) and add your reference to the Resource Library from there, Resharper stops complaining.
A bit of a hack, but the code is never executed and at least you don't need to modify every single controller.
<Application x:Class="Namespace.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Remove Resharper warning about "Resource ... is not found" and allow navigation/refactoring-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Namespace.Infrastructure;component/SystemStyles/Styles.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

ExpressionBlend exception when UserControl contains my custom control

I can edit this UserControl just fine in visual studio but I get this strange exception in expression blend. Does anybody know what should I look for?
UPDATE
I wasn't able to figure how to debug/attach. I did everything as instructed by Mike but no breakpoints got hit. I did more investigation and found that most likely my issue related to themes/generic.xaml
My visual studio solution has project named Infrastructure.dll. Inside that project I have folder themes and inside I have file generic.xaml. Generic.xaml set to compile as resource. My control class lives in a same project.
I have another project named 'Module.dll' and that project references Infrastructure.dll
When I open view with my control (view is from Infrastructure.dll) it works in Visual Studio but gives this error in Blend.
I can drag/drop control in Blend and it would give same error. I tried to remove line where I apply template to control (template in generic.xaml) and it works.
Template is good, I created it using Blend and copied to generic.xaml myself.
When I create view INSIDE Infrastructure.dll and drop my control on that view - it works.
So, my conclusion is that Blend doesn't see template inside generic.xaml that lives in referenced project. How do I fix this?
Open your project in Blend (but do not yet open the problem file). Also open your solution in Visual Studio (order of opening is not important). From Visual Studio, select Debug -> Attach to process... and select Blend.exe. Make sure you're breaking on all exceptions. Once the debugger has finished attaching and loading everything, open the problem file in Blend. The debugger should (hopefully -- hard to tell from the exception details) stop at the problem area in your code.
Issue was definitely related to Blend's inability to read/locate generic.xaml
Visual studio doesn't have this issue btw. I found workaround for now - will gladly accept another answer if I can avoid doing that..
After I add resource reference to view - everything works in Blend. This means I have to add this XAML to all my views..
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Infrastructure.SL;component/Themes/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>

Can't find type 'ResourceDictionary'?

I have the following XAML as a resource dictionary but Visual Studio 2008 is telling me that it can't find the ResourceDictionary tag.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Views="clr-namespace:Locate.Client.Views"
xmlns:Presentation="clr-namespace:Locate.Client.Presentation;assembly=Locate.Client.Presentation">
The specific error message is Error 1 The type 'ResourceDictionary' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\dev\Locate\src\Locate.Client\Views\..\Resources\MainWindowResourceDictionary.xaml 1 2 Miscellaneous Files
.
Any reason why it can't find this tag?
looks ok to me.
Vs2008 is buggy when it comes to using with XAML. try to upgrade to 2010 if you can. if you still using VS, make sure you got latest SP
otherwise, try to reopen, had similar issue in the past, restart fixed it miraculously :) upgraded to VS2010 at the end

The resource "SearchBoxStyle" could not be resolved

I am recieving following error in VS 2010.
I have two Silverlight projects. one project only contains styles and other project is my application. I have referenced styles project in my application and user static resources from that project in my whole application, but I keep recieving this error in VS though everything works fine when I compile and run the application.
The resource "SearchBoxStyle" could not be resolved
Yes, I stumped on this one today and I am also looking for a solution.
It seems to be a missing feature of Visual Studio - VS XAML designer just cannot find static resources outside of the current XAML file.
It seems, Expression Blend is smarter and offers a workaround for such cases.
Here is a similar thread which suggests using Blend:
The resource could not be resolved (VS 2010 RC)
And here is what Microsoft says about this issue:
http://msdn.microsoft.com/en-us/library/bb546934(VS.90).aspx#ResourcesatDesignTime
And for me the solution was to put a / in the path of my resource and set the xaml file to compile as a resource. So my App.xaml looks like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/ControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Dummy Style for WPF 4 bug fix, anything you won't use goes -->
<Style TargetType="{x:Type WebBrowser}" />
</ResourceDictionary>
</Application.Resources>
It failed to load at design time when I did not use the first slash in the path, but now it works fine at design time in other XAML pages.

Can't use WPF designer because can't find custom base window type in XAML, but code behind is fine

I am using a base Window class in a WPF project. In the code behind C# file the assembly to the base type is referenced and fine. In the XAML is looks like this:
<MyNamespace:WindowBase x:Class="MyNamespace.Applications.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNamespace="clr-namespace:MyNamespace.Somewhere;assembly=MyNamespace.Common"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
The solution compiles fine and I can run it. I just can't use the designer in VS 2010. It throws the following exception: The type'MyNameSpace:WindowBase' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well. they have been. I can't understand what this issue is. This particular base class is used in other projects just fine. I grabbed it for a new project and I can't use the designer. Very frustrating.
Found this problem just recently (this answer upgraded from a comment).
If you copy the dll from a network path, you must right click on the file in Windows Explorer, select Properties, then 'unblock'; there is a hidden NTFS stream associated with the file, and many files when you download from the 'net or copy from a network path, for security reasons.
Only the designer complains, yet the project builds and runs fine: weird isn't it?!
Whenever the designer is acting up against me - the first thing I do is clear the obj-folders in the project and rebuild. Sometimes they seem to go out of sync for some reason (usually when I'm drag-dropping a lot of files and renaming visual items).
I dont't know if its the same issue but in VS2008 I tried to make abstract UserControls but had to change this because the designer didnt't support any abstract base classes (however the solution was compilable and also worked as excpected).
Fixed. The library that contained my base class resided on a drive on the network that I did not have permissions to. That seemed to have no affect on VS 2008 as it worked, but VS 2010 apparently took exception to that when the designer tried to load it. Weird.

Resources