Visual studio 2012 XAML designer invalid markup - wpf

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.

Related

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.

Visual Studio design view contains yellow warning icons?

I have created a WPF project in Visual Studio which contains a MainWindow. This "imports" other user controls via XAML. The MainWindow is shown with warning icons and the following text. Unfortunately I don't have the English translation but it means something like this:
This document contains one or more controls which have been changed.
Rebuild the project to show the changes in the design view.
Rebuilding the complete solution does not help. However these warnings do not have any effect.
How can I get rid of these warnings?
I have tried Asryaels solution which is as follows:
Cleaning
Rebuilding
Saving all documents
Closing Visual Studio
Starting Visual Studio
Cleaning
Rebuilding
When encountering the same problem, closing the solution, deleting the Debug and the Release folders in /bin and restarting the solution seems to have helped.
I tried Asryaels solution, but it did not work for me.
Did you switch your platform target? This happened to me when I had project under Platform target: Any CPU and switched to x64. When I switch back to Any CPU warning does not show anymore and control works properly.
If you did switch platform target go to Configuration manager and create a new Active solution platform and for your project set Debug/Release to your project's current platform target. Worked for me.
This happens when the control within the ContentControl changes. You have to rebuild the solution to "update" the content within ContentControl.
<ContentControl Grid.Row="0">
<view:View_UserControl_TitleBar/>
</ContentControl>
In my case I had a User Control Library project that had errors during compilation.
But those error didn't showed up because I was in Release mode.
So changed to Debug mode and the errors were visible, so I could correct them.
After that, the project built correctly and the yellow marks dissapeared.

Visual Studio crashes on opening XAML file

I try and open a XAML file in a silverlight project, VS crashes.
I can create a new Silverlight project, and open XAML files in that new project no problem. However even if I create a new XAML file in my existing project VS still crashes, so my hunch is that it's not the content of the XAML, but rather something else in the project.
Any suggestions on how to troubleshoot this further before I go down the laborious task of starting with an empty but working project, and adding the bits of the existing project until it crashes.
As it turns out my DesignTime ViewModel data was the source of the problem. I inject a design-time repository that populates various collections with suitable design-time data. After a bit of refactoring that was done around the same time as the Silverlight update was applied, I messed up one of the property setters. The validator throw the exception and these caused VS to crash.
In the end I debugged this by starting a second instance of Visual Studio attaching the debugger to the first instance, and setting a bunch of breakpoints in my view model locator and design-time repository.
I debated removing this question, but decided to leave it up, with this answer as I suspect I'm not the first person to have VS crash for no apparent reason.
Deleting the ngen cache worked for me. See What causes Visual Studio 2008 SP1 to crash when switch to Design View of a WPF application
Try deleting the .suo file. You will find it where your solution file is and it will have the same name as the solution file i.e.
MySolution.sln
MySolution.suo
I just had this problem and I solved it this way :
launch the project in debug mode, try then to look at you xaml.
It worked, after closing the program everything was alright.
It's quick and safe. (you don't delete any hidden files...)
Maybe it will work for you.

Visual Studio 2010 Designer Error on Run

I am using using VS2010 and if I have a form open in designer mode and run my application the designer tab will no longer show the form designer but instead an error will be displayed (and it is only fixed by restarting the IDE) saying:
"To prevent possible data loss before loading the designer, the
following errors must be resolved:"
1 Error:
"The designer could not be shown for this file because none of the
classes within it can be designed. The designer inspected the
following classes in the file: ##### --- The base class ##### could
not be loaded. Ensure the assembly has been referenced and that all
projects have been built"
I then shows the following call stack:
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
Any help is greatly appreciated this is really annoying.
Thanks,
Joel.
I get this visual studio bug too now and then, and I deeply ignore the error text, instead I do the following:
Close the Design-tab
Reopens the Design mode by double click in Solution Explorer, or by right clicking Source code tab and select View Designer
Suddenly everything works again!
If not helping, you may have to change bullet 2 into:
Close and restart Visual Studio.
Maybe this can help you out.
I usually close the visual form, rebuild the solution, right-click then select "view designer" in the form code.
Very, very annoying. I am thinking of dropping back to VS2008.
Close the form. Clean the solution. Rebuild the solution. Reopen the form. Worked for me when nothing else would.
I had this same issue and I was able to resolve this by creating new project and then compiled and run the project and then I imported all the files and ran the project again and automatically it was working again did nothing extra.
I'm able to avoid restarting VS by doing the following
Add a new user control
Drag and drop some of your custom user controls on to it (If it gives you an error, build the solution again).
Reopen your control.
In my case, I have a winforms project with several custom controls that are used by other custom controls. Whenever I open some of those custom controls, I get a the "The base class ..." error. Adding a new custom control, building the project and then adding some custom controls from my project to the new custom control allowed me to open the custom controls that were giving me the "The base class ..." error.
UPDATE: I think I found the problem. My controls were not 'added' properly to the csproj file. In the csproj file, the files for partial classes of UI controls/components need the 'DependentUpon' attribute.
E.x.:
before:
<Compile Include="Windows\Forms\DataGridView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Windows\Forms\DataGridView.Designer.cs" />
after:
<Compile Include="Windows\Forms\DataGridView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Windows\Forms\DataGridView.Designer.cs">
<DependentUpon>DataGridView.cs</DependentUpon>
</Compile>
I had a situation where a custom user control appeared to be creating the error (not sure why) so I removed references to the user control from the form and the error went away.
It seems that after installing SP1 the problem has gone away.
Thanks for your help everyone.
I had the same problem using A control With Generics
MvpUserControl<Presenter,IViewMode> : UserControl
what I do it's Remove the Reference and Add again, Clean and Rebuild the Solution I Hope this can be useful for anybody else
I had the same problem with VS2010 SP1. Finally using Windows Update I saw some updates for Visual Studio and .Net, I installed them and is not happening any more.
Old post, but for those whom may find this...
Just ran in to this error and for me it was relatively simple fix.
Found that it may have something to do with the names of your classes, and renaming the problematic class to a higher order. That is the alphabetical order it appears in the assembly (Where A is higher than Z).
MSDN Article
Good luck.
This error occur if the Form class is not a first class in the file, for example if there is some helper class at the beginning of the file.
To solve this issue, move all other classes except Form class to the bottom of the file.
Don't code in Form1.Designer.cs. Move your logic to Form1.cs (hit F7 on Form1.cs [Design] tab).
"In the project file (.vcxproj), locate the entry for the target
Framework version. For example, if your project is designed to use the
.NET Framework 4.5, locate
v4.5 in the
element of the element. "
(Microsoft)
In my case the "v4.5" didn't exist so I add it, and everything is good now.
I tried clean solution and re-build solution and worked for me.
Hope this help!
This solution works fine, please follow these steps below to solve your problem:
Check the reference if load correctly
Clean the solution and rebuild again
Clean the project and rebuild again
Clean your project and open it again
I was login as administrator in visual studio . I just close my visual studio and again open it without run as administrator and my problem is solved
I ran into this today after upgrading VS2019. I went to properties, configuration tab, and set the projects to Configuration = Debug, Platform = Any CPU. Then it worked.
I faced this issue.
To prevent possible data loss before loading the designer, the following errors must be resolved:
I found solution for this problem:
Close all open tabs, and refresh (sync active documents) the solution.
For more information, you can see this video : https://youtu.be/Q3x2HBd7BDs

Visual Studio 2010 WPF Designer issues

I am using:
Visual Studio 2010 Professional,
Silverlight 4 Toolkit
The WPF Designer don't show (invisible) - while the Component Toolbox is showing the relevant controls, and the Windows->Windows option shows the designer to be active. It does this with ALL XAML for me, regardless of its complexity. I have already tried the /ResetSkipPkgs to no avail. I had CodeRush and DevExpress installed (demo) version but removed both since. I can get along with XAML by switching to Source Code /Text Editor, but this really boils my chops to run the app to find out that I have made a silly mistake in my XAML (while a preview would sort it out quicker, and no, please don't suggest Expression Blend for it is non-nonsensical for me to switch continuously between these applications).
When I however switch the WPF Designer to open with Encoding I get the following error - which I assume is related to the issue for not showing the XAML Editor/Designer in non-encoding:
An Unhandled Exception has occurred
Click to reload the designer
System.NullReferenceException
Object Reference not set to an instance of an object.
at MS.Internal.Providers.VSDesignerContext.VSDesignerContextHolder..ctor(IServiceProvider services, VSDesignerContext context, Object docData)
at MS.Internal.Providers.VSDesignerContext.GetContext(IServiceProvider services, IVsWindowFrame frame, Boolean createIfNotExist)
at MS.Internal.Designer.TabbedEditorPane.MS.Internal.Designer.ITabbedEditorService.get_DesignerContext()
at MS.Internal.Designer.DesignerPane.InitializeDesigner()
I have googled it silly, to no avail. I am thinking about reinstalling Visual Studio - but this REALLY is a last resort. I hate fixing things by reinstalling, rebooting etc.
Any guru with the magical answer?
I got the exact same exception today and solved it by killing a few GDI hungry apps. You can see the number of GDI objects a process is using in the Processes tab of Task manager (you will probably need to add the column using View -> Select Columns).
Hmm, I know this is old, but you should try installing SP1 for your Visual Studio if you haven't yet.

Resources