How to avoid "random" errors in WPF Designer in Visual Studio? - wpf

I do often work with custom Controls in WPF.
I usually define them using a xmlns:
xmlns:libcontrols="clr-namespace:innerNamespace;assembly=Assemblyname"
This works pretty fine, but sometimes Visual Studio simply seems not beeing able to resolve the classes or whatever. In this case I get errors like
"The name '' doesnt exist in the namespace ''" - for Controls beeing used
"The tag '' doesnt exist in namespace ''" - when using inheritance through xaml.
"Cannot locate resource ''" - when a control is not displayed in the designer
Most times a rebuild solves this issue, simetimes I need to restart VS or rewriting it. Everytime those issues do show up when I am NOT even editing those files.
I have no clue why this happens and mostly I dont really know what really solved the issue when it's gone, but sometimes it really takes a lot of time i could use to working, so I'd be glad about any hint or trick no nomore waste anytime for that.

These are designer issues, you can try to fix them by closing XDesProc.exe from TaskManager. After the process is closed you will be able to reload designer from visual studio. Rebuild and it should work fine.

Related

WPF Ribbon not displaying correctly in Designer [duplicate]

I'm using thbe Microsoft Ribbon for WPF (System.Windows.Controls.Ribbon) and VS2015. Since I removed unnecessary depencies from my project (like Dynamic Data Display etc, things not related to the ribbon) it does not render correctly in the Designer anymore. All RibbonButtons get rendered as usual buttons and so on.
I used the Clean Solution option and also rebuild multiple times, without sucess. While execution everything is fine, just the designer can't handle the ribbon anymore. What could have caused this strange behaviour?
This is how my ribbon looks now in the designer:
And this is how it's supposed to look and looked before:
Update: it clearly seems to be a visual studio bug, as I opened the project on another machine with the same VS version and there everything is fine.
deleting %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache wasn't working but this:
close solution (at best every instance of VS, you never know)
delete bin\ and obj\ in solution folder ("Clean Solution" isn't enough nowadays. Why should it? It isn't anything anyone would ever do if VS is doing strange things. Maybe I should fall back to kill -9 devenv.exe && git clean -fX as default m( )
Reopen solution and hope for the best.
This drove me nuts. The only real google hits for this problem was this SO question, another one without any answer, 500+ pseudomirrors of SO and thousands of false positives... sorry for the rant.
The problem was resolved by clearing the Visual Studio Designer Cache.
This is done by deleting the subfolders in %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache

System.Runtime.RemotingException in simple XAML file

I have a WPF application which is giving me a very very annoying error
System.Runtime.Remoting.RemotingException
[12068] Designer process terminated unexpectedly!
The number between [] changes each time
The XAML is very simple
<UserControl x:Class="STC.Reports.ReportGenerator.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</UserControl>
This has wasted me hours and hours
Does anyone know anything that could help?
I cant get any more information than that above
Even though I have told VS to break on these Exceptions it doesnt
I have also tried to attach another VS and that makes no difference
I have repaired my installation of VS (2012 Professional)
I have also updated to Update 3
This is even happening when I create a brand new WPF application
Everything seems fine initially, then VS just hangs and the remoting error occurs
Paul
What kind of message are You getting?
If it is a Messagebox when You try to use designer - it is a known issue since VS2010 as far as I remember. It is frequently caused by a video card or its driver, so the easiest way is trying to update your video driver or use some older version. Sometimes that help.
The other way is not to use built-in designer. As for me, I wite pure xaml and it seems to be more convenient and faster way of development. Or, if You like visual UI - You may use Blend. AFAIK it is a part of VS2012 now.
I had this error occur for all windows/controls in a project, even if they were brand new empty windows. I had a markup extension causing a design-time exception (with no indication of this from Visual Studio) and I would get this designer error if I used the markup extension in any project resource dictionaries.
Old post but might be useful for future developers who run into this kind of problem.
I had this exact behaviour. Turned out to be a problem related to my viewmodel. At runtime everything works, but at design time VS will try to load the viewmodel standalone and things got haywire. My viewmodel depended on some global object which I created elsewhere at application startup. Loading the viewmodel standalone creates a exception since the global object was missing.
Quite easy to detect actualy. Just test your viewmodel by instantiating it yourself from code. If it fails VS won't be able to run the designer as well and as you see VS unfortunately won't tell you what happened.

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)
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.

Visual studio 2012 XAML designer invalid markup

I've got a project that contains usercontrols. For some reason, the design view for the window which uses the said controls has stopped functioning and insists on "Invalid Markup" - the error given is that some members of the usercontrols are not recognized or not accessible. The project however compiles and executes just fine. Loading it up in VS2010, the editor works fine, no errors whatsoever - the same even in Expression Blend.
So far I have tried the typical clean, rebuild, manually deleting stuff from obj, updating the .xaml and rebuilding, tried starting VS2012 with /resetuserdata and /resetsettings - the problem persists. I even rolled back to a much older revision of my project, back when the designer was working just fine, no dice - same error. I also tried launching VS2012 as a new windows user to avoid any stored appdata that might be lingering, again a no go.
Is there some other sort of cache or something that I could manually delete?
There's also an issue with the ShadowCache (used for rendering designer) getting out of sync with your XAML in VS2012. I just found this out, as I was having a horrible time with the following error with derived user controls:
The local property XXXX can only be applied to types that are derived from YYYYY.
The shadow cache is located in your user profile directory:
app data\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache
You can delete everything in there and restart VS2012. After that, things worked much better (for at least a while!)
Delete everything in ShadowCache
C:\Users\username\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\
Copy-pasteable paths
Just copy/paste one of these paths into Windows Explorer. %LOCALAPPDATA% is a Windows Environment Variable it will be replaced with the corresponding value when entered into Explorer (also works in Command Prompt)
VS2012
%LOCALAPPDATA%\Microsoft\VisualStudio\11.0\Designer\ShadowCache\
VS2013
%LOCALAPPDATA%\Microsoft\VisualStudio\12.0\Designer\ShadowCache\
VS2015
%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache\
ASP.NET
If you develop ASP.NET also delete
%LOCALAPPDATA%\Microsoft\WebsiteCache
%LOCALAPPDATA%\Temp\VWDWebCache
I'm not sure this will fix all cases but this is what worked for me (all the time now).
I have VS2012, using the Blend designer in the IDE, building an x64 application, when I would define a new ICommand and add the Command attribute, I would get the designer isn't supported in x64 error (I forget the exact warning). If I switch to x86, I'd get invalid XAML markup errors complaining the the ICommand wasn't recognized or was not accessible, no matter how many times I rebuilt in x64. If I switch to x86, build, then switch back to x64, voila, not problems with the designer.
Now I recall similar issues with VS2008 and Blend version 3 and 4. From what I've read in other posts, using Any CPU might also resolve the issue.
May be you have added user controls which are not supported or you might have added some wrong parent-child relationship in your user controls . Try removing the suspected User Controls and rebuilding the project . It must fix the issue .
Cheers
You need to re:encode your xaml, open bugged files in ide -> save as -> save encoded (choose UTF8)
I've the same problem while using controls with a custom (no param) Constructor.
Check if the Custom/User Control constructor doesn't require any data that the WPF designer doesn't have. A quick wait to check that is surrounding the whole thing with a try catch, cleaning, rebuilding and then check to see if the problem is solver.
If it is not, try commenting everything except the default WPF Init cod, clean, rebuild and test it out.
In Visual Studio 2013 this is a workaround I using for my Windows Phone Project, http://danielhindrikes.se/visual-studio/workaround-for-invalid-markup-problems-when-developing-for-windows-phone/. I guess it is the same designer that is used when you writing XAML for WPF.
Have tried to delete Shadow Cache but itjust work first time I start Visual Studio, above workaround is the only thing that helped me.
A little late, but something else to consider: If your no-parameter constructor is doing some other work, like getting data that doesn't exist because you are in the designer, add this at the start of your constructor:
if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject())) return;
// Do work.
This is necessary because the designer does execute your no-parameter constructor which may fail in design mode an give you the invalid markup.
And, regardless of what others are saying, this is not a VS or WPF XAML Parser bug. I ran into this issue today using VS 2015, .Net 4.5.2.
I just had the same problem (program compiling and running fine, XAML designer reporting invalid markup), the issue was that I had accidentally changed the assembly name of one of the projects in my solution, I changed it back and my XAML designer sprang back to life, so check the Properties page of each project in your solution, and ensure the Assembly Name is as you expect it to be.
I think there is no problem in your project, but it is problem in VS 2012. Try to install the latest update for VS 2012 (Update 2) and also check this answer.
Regards,
I have the same Problem with VS 2015 and 2017 but only if I compile for x64 only.
Here it helps if I change compile target (Project properties - Build, its called Plattformziel in german) temporarily to x86, compile to project and switch back to x64.
Maybe this is a "solution" for anybody else.

Unable to use usercontrols in my project

I'm working on a WPF solution. For some odd reasons, I'm getting the error "The type '...' was not found. Verify that you are not missing an assembly reference..." every time I add a usercontrol/custom control through XAML. I did build the solution, had the namespace declaration for XAML, made sure I had the correct assembly name, and made sure that the usercontrol itself doesn't contain any errors.
What's even weirder is that, when I ignore the errors and add the controls manually through the XAML editor (heck, even InteliSense in the XAML editor works), then build & run it, everything works (I'm guessing this means that there's no problem with the solution itself)
The controls show up in the toolbox, but I can't add it through the designer. As I stated, adding through the XAML editor/in code behind works, but it's really inconvenient. Adding through the XAML editor also raises the error, and stops the designer from loading, so it's even more annoying. Adding through code behind is just inelegant, and makes it hard for debugging.
EDIT: Opening the solution on a different computer doesn't solve the problem, so it's not a problem caused by Visual Studio. Also tested moving everything to a new project, still doesn't work, which means it's not a problem with the configurations, likely a problem with the code. If then, how come it builds & runs, and even IntelliSense works and the designer doesn't?
Okay...nevermind, it's because I built it for x64, and apparently the designer just doesn't work with that since it's x86. Using "AnyCPU" seems to work.

Resources