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>
Related
I am attempting to use the WPF Extended Toolkit. I downloaded it and it is currently sitting in my project folder.
I right clicked the .dll file and checked "Unblock" following this answer. I have it referenced in my Visual Studio project.
I have it named WPF Extended Toolkit in my Toolbox.
I have the namespace in my XAML file.
When I try to use it in my XAML file, I'm getting the blue squiggly line stating, "The type toolkit:BusyIndicator was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."
I'm very new to this, since I've only used what was available by default in WPF apps. Can someone tell me what I'm doing wrong? I thought I covered everything needed to get this going.
I figured it out! I found this answer!
Before adding the namespace, I rebuilt my project, then I added the namespace. IntelliSense picked it up and I was able to add my Busy Indicator.
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)
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.
Just delete subfolders in
%LOCALAPPDATA%\Microsoft\VisualStudio\12.0\Designer\ShadowCache
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.
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.
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.
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.
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.
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.
i have a project that i am doing and i need to share the code between silverlight and WPF Assembly problem is that even though the wpf assembly is the owner of that file
and the silverlight assembly only has a link to the file, all of the build actions are page everything is correct. if i make the silverlight assembly the owner then silverlight works and wpf doesnt, and currently with wpf being the owner i dont get any errors at all it just never styles the control like it cannot find it..
Note: both projects exists in the same solution.
this scenario builds and runs fine
wpf project
|__Themes
|__Generic.xaml
|__SomeControl.cs
this scenario builds and runs but will not display the control
if i change them from linked to normal it will work fine.
i just want to share this source code and not have multiple versions of the same file floating around.
SilverlightProject
|__Themes
|__"Linked"Generic.xaml
|__"Linked"SomeControl.cs
sorry for my corny Tree view representation
+++++++ UPDATE +++++++++
i have noticed when using any linked file regardless of if it is silverlight or WPF
the link file will not build into the Themes folder in the resource only the root.
i used reflector to see where my resources ended up after compilation of the assembly including the linked file and they ended up in the root , so with that being said. is there a way to prevent this or a fix for this if this is indeed non intended behavior .
i would really love to get this figured out as it has been driving me insane for a while now.
Silverlight XAML and WPF XAML do not have the same namespace - so they aren't directly reusable.
My mistake - you're right - now with Silverlight 3 the namespaces are the same:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml
What is the Build Action in the Property Pane for the XAML?