Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: VS2012 designer shows "The component 'XXX' does not have a resource identified by the URI YYY"

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)

like image 743
tete Avatar asked Jul 11 '13 11:07

tete


3 Answers

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.

like image 77
o_weisman Avatar answered Sep 21 '22 17:09

o_weisman


Just delete subfolders in

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

like image 41
Hamed Zakery Miab Avatar answered Sep 19 '22 17:09

Hamed Zakery Miab


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.

like image 38
Tom Deloford Avatar answered Sep 20 '22 17:09

Tom Deloford