Not able to open a form in design mode - c#

When i open form, i can't get into design mode and i get this error:
The variable 'MonthViewCalendar'
(internal
Infragistics.Win.UltraWinSchedule.UltraMonthViewSingle
MonthViewCalendar;)
is either undeclared or was never assigned.
Any idea why a form doesn't go into design mode? I am using VS 2010.
I tried - Clean solution, restarting VS and reopening, but that didn't solve my issue.

Sometimes you may find that the project file loses the correct subtype that the file needs to open in design mode.
To fix:
Shutdown VS, then edit the projects ".csproj" file using a text editor
Look for the <Compile Include="MyFile.cs">
If there's no "<SubType>Form</SubType>" then add it back in as follows
<Compile Include="MyForm.cs">
<SubType>Form</SubType>
</Compile>

Go into your Form.Designer.cs file and remove the declaration for "abcd". Then reload it in your designer.

It can happen if you insert a new class above an implementation of the class.

What works for me is to close and relaunch Visual Studio, then rebuild. After that the form can be opened in design mode. I wouldn't say I particularly like my solution, but I haven't come up with a more sure-fire solution.
Edit: I've only ever encountered this problem when there's an Infragistics control on the form.

Related

C# EnvDTE and TFS massive problems

I have created a vsix plugin for VS 2015 that receives some data of a REST-Service, writes it into a file and then it adds the file to my C# Project.
Well the problem is that after the files were written on the file system and integrated to the project my user input in visual studio is blocked:
e.g. I can write for example "asdf" in a code file, but when I try to delete the text with the backspace button it is not working. Other buttons like CTRL are also not working.
The interesting part is when I close VS2015 the following error appears:
The problem is definitly caused by this line:
project.ProjectItems.AddFromFile(filePath);
project is an EnvDTE.Project object! The thing is the files were added to my project but I have to kill and restart VS to continue with my work.
I have also found a little workaround: When I disable TFS in my project all is working fine!
So my conclusion is that the problem is caused by TFS!
Can anybody tell me what I can do, to solve this problem! It costs me a ton of time to restart VS every time!
When using TFS, you need to checkout the project for modification first, use SourceControl.CheckoutItem: https://msdn.microsoft.com/en-us/library/envdte.sourcecontrol.checkoutitem.aspx
The problem here is not what you are doing, but how. Some modal window you are opening it's been locked to the screen. Make sure you closed it correctly.
This behavior it's common when using modal. Try to figure it out what window you are opening and try change it from modal to not-modal.
It will stop this problem.

Changing Project Metadata in Visual Studio 2013 C#

I've got a Visual Studio 2013 package written in C# where I need to make some changes in the items and their attributes in a C++ project file while Visual Studio 2013 is running and has the project loaded. Actually, it could also be OK to save the project file at the point when the whole solution is being saved.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="Test">
<MyItemToChange Include = "TestItem">
<MyMetadata1ToChange>Value1</MyMetadata1ToChange>
<MyMetadata2ToChange>Value2</MyMetadata2ToChange>
</MyItemToChange>
</ItemGroup>
<!-- The rest of the file -->
</Project>
In previous Visual Studio versions I used the Microsoft.Build.Evaluation.Project class to change the items and the metadata of the project. When you have the reference to the project, you can either accessed the XML structure of the project directly through Project.Xml property or get a hold on different Microsoft.Build.Evaluation.ProjectItem and use the interfaces found there.
However, since Microsoft has changed the structure of Visual Studio in their 2013 release, though the Microsoft.Build.Evaluation.Project is not deprecated, you can't access the C++ projects any more through Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects as the collection is empty. However it still works if you want to access C# projects. (As a matter of fact, browsing deep into the objects while debugging you can find that they still use the same Microsoft.Build.Evaluation namespace for inner representation.)
Since I can't access the Microsoft.Build.Evaluation.Project any more, I need an alternative to
access the project otherwise than using the
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects
write project items and metadata while Visual Studio 2013 is running.
Unless I've missed something, the following are not good for my purposes:
Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetItemAttribute sets only attributes to items that are displayed in the Solution Explorer. "MyItemToChange" is not displayed in the Solution Explorer
Opening the file and manually editing and saving it. Unless you know how to suppress Visual Studio's warning about a changed project and how to auto reload it, it is not a way to go.
Note: You can close the solution, open the project file manually, edit then save it and reopen the solution. It would work fine, the data is there, unless the files are under source control. Now it opens up a whole lot of new issues (why EnvDTE.DTE.SourceControl.CheckOutItem() doesn't work, etc.) So I still think I would be better off if Visual Studio would handle writing data to the project file.
Reflection. Yes, as I mentioned before, I could dig into internal classes to get a hold on the "original" Microsoft.Build.Evaluation.Project, and Microsoft.Build.Evaluation.ProjectItem, but first of all, it is quite unsafe for future uses and as far as I remember, you cannot be sure that if you modify these now internal classes, the project will know that it is dirty and has to be saved.
I'm glad to have any suggestions as I'm really running out of options.
Thanks.
Well, I have worked out a workaround, not a real solution for the problem.
What I do right now is the following:
Ask the user whether they're OK with closing the whole solution and saving everything. If not, I cancel the whole procedure: EnvDTE.DTE.ItemOperations.PromptToSave
Try to ask Visual Studio 2013 to check out the project file for me in source control using EnvDTE.DTE.SourceControl.CheckOutItem() method. If it throws an exception (NotImplementedException), I use a bodge to check out the project file. That is, I write a custom property into the project file using Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetProperty() method.
Close the whole solution. EnvDTE.DTE.Solution.Close()
Open the project file using the System.Xml.XmlDocument class. Edit. Save. Oh, and remove my silly property written in the 2. point (the one used to force Visual Studio 2013 to check out the file in source control.)
Reopen the solution. EnvDTE.DTE.Solution.Open() At this point the user might be asked again to confirm some source control options.
Why is it just a workaround not a proper solution?
It's ugly. :)
Methods are abused for things they are not meant to be used (writing a random property into a project just to force source control checkout)
It wouldn't work if closing the solution / project is not an option. E.g.: if you need to save something during build or while they are editing the solution / project / source files; or if you have to do it often not just once during the lifetime of a project.
I'm still looking for the proper solution for the problem. But until someone could tell me how it is done, I have to live with this current implementation.

Unable to get the designer view window back using windows forms with Visual Studio 2010

I am in process of writing a C# Windows Forms application using Visual Studio Express 2010 ENU SP1. Further VS specifics are at the bottom of this post. I recently made some changes using the designer view to the layout and then decided that I did not want the changes so I closed the designer window. The code window was still up when I closed the project and the changes were saved any way. I don't care about the changes because the layout can be restored easily except for the fact that I cannot find any way to reopen the visual designer window. To get the window back I have tried the following:
Shift F7
Right click in the designer code window
Double click the designer file under the solution explorer
Select the designer file under the solution explorer and use the context menu to bring up the file
I have an evaluation copy of the VS 2010 Team and it displays exactly the same behavior when utilizing my project
I have tried a backup copy of the project but it displays the same problem in both the Express and Team versions
I have been all over the MSDN, VS forum, and the internet at large and not found any solutions
When I first started the project I did rename the Form1.cs file from within the solution explorer because I wanted to have a different name than Form1 for the application. When doing this it asked the following:
"You are renaming a file. Would you like to perform a rename in this project of all references to the code element 'projectname'?
I replied yes. So now I don't have a Form1.cs file but a file with my "projectname.cs" and the designer file named "projectname.Design.cs. This is the only change that I made that I can think of that might be relevant. I did try renaming it back to Form1.cs but that also did not resolve the problem.
I have to say that I am new to using Visual Studio. So far I like it quite a bit but I am dead in the water right now and unless I can get this resolved I will lose two weeks worth of work. Any assistance would be greatly appreciated.
Thanks,
-Tom
Additional Details:
Windows 7 Professional SP1 32 bit x86
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel
Installed Version: C# Express
Microsoft Visual C# 2010 01014-169-2560017-70726
Microsoft Visual C# 2010
Microsoft Visual C# 2010 Express - ENU Service Pack 1 (KB983509) KB983509
This service pack is for Microsoft Visual C# 2010 Express - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
I realise this is quite an old thread now, but I just had something similar happen in one of my projects in VS2010. There was no way to edit the Form in the form designer.
In the end tracked it down to a problem in the .csproj file. There is a item group that specifies what is compiled. Within the item group tag, for my form it had ...
<Compile Include="AreaChart.cs" />
it needed...
<Compile Include="AreaChart.cs">
<SubType>Form</SubType>
</Compile>
The SubType XML tag was missing. A quick change to the project file and I could edit the form again.
Just one more way to screw up the form designer - I had something like this:
namespace MyProgram
{
public struct SomeStruct {
int a,b;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Turns out you can't put the SomeStruct definition there even though everything works fine and there were no errors. Once I moved it, I was able to see the designer view again.
Again it is an old thread but web interest indicates that numerous people are still having this problem and it has not been solved.
I am using VS2012 and had the problem when I copied a library control which spawns 3 forms into a separate library for further development. All controls in the forms displayed perfectly when run but the designer displayed a blank form.
The problem was not as above (that was intact) but, thanks to this hint, I added a new form and compared the entries in the .csproj file. For each of the copied forms, an entry akin to the following was showing:
<Compile Include="MyForm.Designer.cs" />
What was needed was:
<Compile Include="MyForm.Designer.cs">
<DependentUpon>MyForm.cs</DependentUpon>
</Compile>
Adding these manually for each form solved the problem.
Make sure you don't have any class declared before your designer partial class. The .cs file needs to have the partial designer class as the first class in the file.
public partial class frmWidget : Form
{
}
public class SomeClass
{
}
Now SomeClass cannot be on top of the partial frmWidget class. Once you re-arrange that then it will automatically fix the designer issue and no need to restart VS or re-create the form. I hope this helps.
Tried all the suggestions mentioned in this question, nothing worked for Visual Studio Community 2017
no Shift-F7 shotcut
no context menu item visible
no double clicking on MainForm.cs
no wrong class order inside MainForm.cs
no wrong entries in mysolutionname.csproj file
But this worked for me
Right click your MainForm.cs file (or 'Form.cs' depending how you named it)
'Exlude from project'. This temporarily removes MainForm.cs, MainForm.Designer.cs and MainForm.resx
Use 'Add ยป Existing item' and select MainForm.cs. This will re-include all three files.
Of course you should add them back to the same folder as they were before
Double click on MainForm.cs and Design view magically openes
I had the same problem but mine was caused on VS2012 by dragging and dropping some of the forms into different folders.
David's solution above was helpful towards fixing it, but didn't go all the way.
If you have the form in a sub-folder the Compile Include line should read like this:
<Compile Include="SubFolderName\MyForm.Designer.cs">
<DependentUpon>MyForm.cs</DependentUpon>
</Compile>
Please note that the sub-folder name is needed in the first line but not in the second line.
I also had to change the EmbeddedResource line further down the file to associate the resx file:
<EmbeddedResource Include="SubFolderName\MyForm.resx">
<DependentUpon>MyForm.cs</DependentUpon>
</EmbeddedResource>
Again, note that the first line mentions the sub-folder whereas the second line doesn't.
Thanks for the thoughts. I just completely reinstalled both the Express and evaluation copies of the Team versions of VS 2010 and it is now magically working. I have no idea what caused the problem nor what fixed it but I'm now back on track. I probably should have done that before asking on this forum.
I had the same problem with VB. Thanks for the hints. I found the same issues in the .vbproj with my UserControl.
I had this in the .vbproj file:
<Compile Include="AddCommunicationTask.vb" />
And changed it to this:
<Compile Include="AddCommunicationTask.vb">
<SubType>UserControl</SubType>
</Compile>
When I reloaded it I was still having problems and realised that I had written another class in above the form class, this was causing the error. The form class must be first. All I had to do was move my class down and make the form class the top one.
I hope this helps others - good luck!
p.s - I am using vs Community 2015
I had the same issue since I had created the project as a C# Windows Form App (.NET Core) I decided to create it as a C# Windows Form App (.NET Framework) and I can now see and use the Designer. Note the difference between using 'Core' vs 'Framework'
I hope this helps you out.
I realise this is a really old thread now, but I had the same problem and it turns out there is another node that can go astray in the csproj file; the form .resx has an EmbeddedResource node and mine was missing the subnode Designer. This allowed me to see the form code again in the IDE.
I had a similar issue, but not quite the same.
I copied a form from one project to another (using windows explorer) and then added it to the new project by right clicking on the project in VS and choosing > Add > Existing Item.
My mistake was to add all three files for the form (.cs, .designer.cs and .resx). I should have only added the .cs file.
Although this is quite an old thread, I want to share my case and the solution.
I had the same problem but I used Telerik WinForms component for my Form. I couldn't see the designer until I realize that the design-time capabilities of RadControls for WinForms are implemented in the Telerik.WinControls.UI.Design.dll assembly. Then I add the reference and now the designer shows up.
I had the same problem and I got the (Design) window back by double clicking the Form1.cs file in the Solution Explorer (not the Form1.Designer.cs file).
I accidentally deleted my Form1[Design] file. Double clicking the Form1.h file did nothing. The program ran and the Buttons TextBoxes and Labels were all there just no Form1[Design] was visible to edit. I fixed it Under: Header Files select Form1.h and go to Form1.H file properties. Under File Type from the drop down change it to "C++ Form" I closed and restarted the program. You should now be able to double click Form1.h and see your Form1[design].
I had the same issue in VS 2010. I was not able to view the designer form(Connect.CS).
i already had the
<Compile Include="Connect.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Connect.Designer.cs">
<DependentUpon>Connect.cs</DependentUpon>
</Compile>
tags in the ItemGroup Tag, but still i wasn't able to view the Designer.
I was using name space directive 'Using RFCOMAPILib', which already had a Form element in it and it clashed with the System.Windows.Forms.Form.
After replacing 'public partial class Connect : Form' to 'public partial class Connect : System.Windows.Forms.Form' im able to view the Designer now.

Visual c# nothing is appearing

This might sound extremly strange, but i have no idea what to do.
Visual studio 2008
c# windows form
I've been working on a project for a while, and it's all been rosy. Now, anything i add to the windows form in terms of labels, picturebox's ect don't appear at runtime. They are visible in the designer view, but do not appear at run time. Now, even when i move things that were already there, they don't move at runtime.
I'm guessing this is the cause of a windows update messing with visual studio again, but i can't find anything on the problem
Just a note, The project runs exactly how i left it yesterday every single time. Regarless if i move objects, add labels.
Anyone know of anything like this, know of a fix.
Thank you
I think you should Clean your solution and then rebuild it.
As you are using Express Edition, Clean option might not be added by default.
Go to Tools -> Settings and Select "Express Settings".
Now go to Tools -> Customize. And select Commands tab in the dialog.
In the dropdown next to Menubar radiobutton, select Build.
Click on AddCommands and add "Clean Solution".
Now you can go to Build -> Clean Solution. And then rebuild the project.
One time, I found the .suo file of the solution corrupted for unknown reasons.
Delete or rename it, then try again ?
The designer for classname.cs rewrites classname.designer.cs. View the code of the designer.cs and see if your changes are actually being saved into this file. Try hand-editing this file (change a label string or something else easy to spot at runtime).
Maybe the designer.cs file is read-only or perhaps there is a design-time exception that prevents saving the new .cs. I have run into issues like this when I had third-party component libraries in a project and the third-party designers were crashing.
Did you perhaps remove the call to InitializeComponent() from your Form class constructor?

Form showing as a class in Solution Explorer

I have a form in my project that is showing up as a class in Solution Explorer. This is causing a problem since I can't get to the designer. Any ideas on how to fix this?
You can fix the problem manually by editing your csproj file.
Open it in notepad and search for the filename of the class. You should see something like this...
<Compile Include="frmTest.cs" />
Add a subtype called 'Form' like this...
<Compile Include="frmTest.cs">
<SubType>Form</SubType>
</Compile>
Reload the project. Visual Studio should now identify the file correctly.
Try seeing if there are any hidden files by using the the 'Show All Files' button. Sounds like your project file might not have all of the files added to it.
One thing that has worked for me in the past is to just add another blank form to the project and that seemed to make the other form show up as a form. You can then delete the blank form.
I don't know if it will work for you, but it only takes a few moments to try it.
Chris
remove the reference of form related dll and again add and build the project
Press F7 when in code editor to get to the designer. And restarting Visual Studio usually helps.
Simply select the form and press Shift+F7. You'll find your form.

Categories