I am creating a windows form application in managed C++. To add a custom user control either one can create a new project or add CLR User control to same project. When I add a user control to same project it builds and shows control in toolbar. When I drag and drop it onto my main UI it throws up error.
"Failed to load toolbox item, It will be removed from Toolbox".
There is no error if I create a separate project under same solution and compile control as a DLL. Is there a way I can add a custom user control to same project and use it.
Also I looked up similar question on the topc but none of them has helped me. I have checked the files and I am building the project as Win32 and there is no way control being separately built as x64.
Had same problem after one or both of renaming project or/and changing platform, most posted "solutions" provided to other people asking the same question didn't seem to work.
What did work for me was to go into the project folder and delete the obj folder, and just to be safe the bin folder too, then build again. (Seems the so called Build->Clean menu item only does half of the required work.)
I have a problem. In a Visual Studio 2012 WindowsForm VC++/CLR mixed (/clr) project, after adding a small image to an image list control (ImageList) on design time, when the project is opened again later and the Form Designer opens, the following message appears:
"C++ CodeDOM parser error: Line: 387, Column: 18 --- Unknown type ''. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built."
The line is:
this->components = (gcnew System::ComponentModel::Container());
I close the window with the message, reopen the desired Forms Designer, and everything appears correct.
In addition, open the Designer sometimes fails or takes too long to open.
The forms only fail if they appear when you load the project, but then it shows well. I worry that eventually this will cause a major fault.
Lists of images are on the project from start, but unchanged in a long time, this problem now appears only after deser modified only by adding an image to the list. I returned to a previous version and then left the feature for later work.
Why is this happening? This problem is holding back a lot of visual design changes.
In Visual Studio, there's an option under Tools -> Options -> Winforms Desinger called "Optimised Code Generation". When it's enabled (Which it seems to be by default), the designer is much flakier and throws errors like this. Changing it to false seems to fix the issue (or at least it did for me):
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 am getting the following error on when I try to compile:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets(269,9):
error MC6000: Project file must
include the .NET Framework assembly
'WindowsBase, PresentationCore,
PresentationFramework' in the
reference list.
This project is the Web backend for a Silverlight Business Application with very little modification. When I do add these references, everything breaks. I've tried removing every single reference from my references until all I had left was a reference to System. I still get the error though. In fact it is the only error that shows up.
Edit
Figured it out, and I have a new question: I accidentally moved (dragged) a XAML file from my Silverlight front-end project. Visual Studio is very finicky and will drag something at the drop of a hat. When I click an item, even if I release the mouse right away, sometimes it will drag the item following the mouse. Is there a way to make it less jumpy?
If you copied or moved an item from another project, its "Build Action" property might be set to "Page". This happened to me, and changing it to "Resource" (because that's what the item was) fixed the problem.
I've copied this answer from another site. It was the problem I was facing.
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/7bf38ed6-43f8-492e-a304-0842e6c7c6b2/
I spend most of my time developing controls for both WPF and Silverlight using the same codebase. To do this I add existing files from one project (say Silverlight) "as links" to the other (say WPF). For minor differences I use preprocessor directives like
#if SILVERLIGHT
...
#else
...
#endif
The code in these blocks is grayed out depending on the type of project you've opened the file from. So if you open your file from Silverlight project (where SILVERLIGHT is defined) the else part is gray and Intellisense doesn't work in it.
In order for WPF part to be processed by IDE (with coloring and Intellisense support) you need to open the file from the WPF project. When you try to do that you get a message box saying that "This document is opened by another project" and when you click OK it displays that file in the context of the Silverlight project (not what I wanted to see). So I have to close the file, navigate to WPF project again and open the file again. This is very, very annoying.
So the question is this: is there some sort of setting or add-on that would make Visual Studio reopen the file from the project where I double-clicked on it instead of showing that stupid message box and showing me that file from the "wrong" project?
This has happened to me about twice in a month now, not in a WPF application. No idea why it happens but in both cases the fix was to Clean the solution, reboot the PC (not just restart Visual Studio) and then build the solution.
You could make this a little easier to work with by using partial classes and multiple files: shared code that is the same for both WPF and Silverlight in a shared linked file, and a separate file for each containing the code specific to one or the other (with identical method/property signatures), each of which is only in one of the projects. Doing this allows both the WPF and Silverlight versions to be opened at once (since they're separate files) at the cost of adding a bunch of extra file management overhead.
Beyond that, get some extra memory and use separate solutions.
It occurred to me, when I had one project containing a linked file of other project under one VS solution. When I tried to navigate to the definition of a method in linked file, VS prompted with a message that this document is opened by another project.
To resolve this, I had to unload the project that owns the original file from the VS solution. After that navigating to method definition in normal time and debug time was not an issue.
Yes this is possible using Visual Studio Shell.
First instantiate EnvDTE80.DTE2 object:
private static EnvDTE80.DTE2 _dte;
public static EnvDTE80.DTE2 DTE
{
get
{
if (_dte == null)
_dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
return _dte;
}
}
and then:
// On Document Opening, close the existing instances.
// This event occurs when you double-click file in Solution Explorer.
DTE.Events.DocumentEvents.DocumentOpening += (s, e) =>
{
if(!DTE.ItemOperations.IsFileOpen(YOURFILENAME))
return;
foreach(Window win in DTE.Documents.Cast<Document>()
.FirstOrDefault(s => s.FullName == YOURFILENAME).Windows))
win.Close();
}
// next; VS itself will call DTE.ItemOperatins.OpenFile(YOURFILENAME);
HTH.