17

As the title suggests, this error is thrown by the designer, which means the designer can't display my UserControl correctly which in turn means I can't navigate smoothly from element to element in this UserControl to make modification. Really annoying.

XXX is the name of my UserControl, while the URI YYY is actually XXX's path. So I don't know understand it can't find itself as resource. I googled this error, but most of them happened in the runtime. In my case it doesn't happen at all when I execute it. The description of this error is really not explanatory enough, because I am not sure who in the CLR is loading the file itself as a resource.

Another thing might be worth mentioning is, this error only happens after I build my application project, which the error UserControl resides in. After I click to clean the project, the designer can display the whole stuff (but obviously I can't clean the project every time before I make any change, since the building takes time)

tete
  • 4,859
  • 11
  • 50
  • 81
  • 1
    Same problem here - thanks for the note about cleaning the project. – mola Aug 22 '13 at 08:43
  • I'm getting this behavior specifically with user controls within other user controls. The parent control will render in the designer, but the others will throw the exception. I'm using DevEx WPF controls. Cleaning the project works for me as well. – Erikest Oct 31 '13 at 00:15

6 Answers6

15

It is possible that the control's .g.cs or .g.i.cs file has been corrupted. Try to clean, close visual studio and restart it. I think that helped for me in several cases especially when I copy paste controls from one solution to another.

o_weisman
  • 804
  • 7
  • 19
6

Just delete subfolders in

%LOCALAPPDATA%\Microsoft\VisualStudio\12.0\Designer\ShadowCache

Hamed Zakery Miab
  • 738
  • 2
  • 12
  • 34
1

If you refactor a UserControl down a lower level project that the UserControl was previously referencing then you will see this error.

Removing the assembly reference from the namespace fixes the issue.

<UserControl xmlns:ui="clr-namespace:MyCompany.Core.UI;assembly=MyCompany.Core.UI"

should be

<UserControl xmlns:ui="clr-namespace:MyCompany.Core.UI"

The designer is not smart enough to highlight this.

Tom Deloford
  • 2,055
  • 1
  • 23
  • 24
0

I ran into the same issue, it compiled and ran fine, but the XAML editor/Designer complained. In my case, I found the solution to be that my user control was declared within a namespace in the XAML (x:Class="myNamespace.myUserControl") but not in the code behind. Adding the namespace declaration in the code behind solved my issue.

AXG1010
  • 1,872
  • 3
  • 21
  • 35
0

There is a possibility to debug Visual Studio Designer in the second attached Visual Studio.

See How to troubleshoot and debug Visual Studio design mode errors for details.

Community
  • 1
  • 1
Artur A
  • 7,115
  • 57
  • 60
0

To display the UserControl, the designer has to instantiate the user control. Look for possible Null Reference Exceptions.

In my case the user control had an NRE due to a dependency not being injected. I added handling for the NRE and no more issue.

Greg Gorman
  • 196
  • 1
  • 9