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.
I have an WPF app, all seems to run fine with one exception - the designer rarely, if ever, loads correctly. Usually complaining about Undefined CLR namespace. and then saying it can't find a few of my local: defined controls.
Is this just a defect in the designer or Visual Studios code generation or actually systemic of something wrong with my application?
In your code can be an error which occurs only in design time. It is possible to debug it. See How to: Debug a Designer Load Failure. Shortly you need another instance of Visual Studio and attach it to the one displaying your wpf app. You can even try to follow the error to its roots with How to: Debug .NET Framework Source.
I had a similar problem and I successfully tracked it down to DataContextChanged event handler and got rid of it.
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.
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.
I am trying to learn WPF. I am following along with a book(WPF in 24 hours) and occasionally I get the following error:
Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.
When I click "OK" the application continues to run as if nothing is wrong.So far I have worked with XAML only and have not entered any other code. The examples that I have found so far in SO and google reference specific code issues. Any shove in the right direction would be appreciated.
Oh...I am using VS2008 Pro
I had this when declaring a Style without specifying the TargetType. I cannot remember if that was in WPF or Silverlight2 though.
Old question, but in case it helps someone...
I had this error as a build error in a XAML file of a Template10, MVVM UWP app.
The reason appears to be because I was referencing a ViewModel that is in a separate .dll.
Moved the referenced ViewModel into the app, the build error goes away.