Normally when we add new rows to a .resx file, say Resources.resx, in the IDE's resource editor, the code-behind file, say Resources.Designer.cs, will be automatically updated - adding new properties for the new rows.
But in my situation, that automation has stopped working. Have you met the same problem? If you do, please help me to get .resx back to work :)
Thank you!
A very similar problem arises with aspx/ascx files. This involved deleting the designer and then clicking "convert to web application" to force code gen of the designer again. Don't know if a similar facility exists for the resx.
Here what I found that works:
Delete the Resources.Designer.cs file
In Solution Explorer, exclude the Resources.resx
Then, show all files, re-include the Resources.resx.
The Resources.Designer.cs file should be recreated then.
Reset the 'Access Modifier' to be 'Public' (see details here)
Right click Resources.resx in Solution Explorer and click Run custom tool
Hope this would be helpful to you!
Related
I have IAR Embedded Workbench - ARM 8.20.2 in a production environment and it looks like someone hit something causing the menu bar to be hidden. There are no obvious hamburger menus, dropdowns, etc that I can click on to easily get it back, just a blank barren menu area without a contextual (right click) menu. just above the usual IAR tool bar. I would normally look at the IAR key bindings to figure this out, but.. there's no menu and can't find a shortcut for that. I've spent awhile now googling this without any luck. Does anyone out there know if there is a shortcut for toggling the menu bar?
Thanks,
Matt
I was able to resolve this issue by deleting the PROJECT_NAME.wsdt file from the settings folder in the projects. Thank you to both #user694733 and #Clifford for their help with this.
I found that the menu bar missing applied to all projects in a workspace. To fix it, exited IAR workbench, and deleted the .wsdt file in the workspace folder. Then restarted IARWorkbench and loaded the workspace file. I found that the workspace was reset for all projects in that workspace, and the menu bar was present as expected. Problem solved. Thanks for the previous post about the .wsdt file.
The file Project.wsdt resides in a directory called "settings".
If deleting only the file doesn't help, close the software, delete the entire directory (or rename it, to be on the safe side), and then open the project again.
Yesterday I edited a form in Visual Studio's form designer. When I returned to it today, the designer shows nothing. I can open the properties window, select all the different constituent components and edit their properties, but they do not show up. The application builds fine and the form can be run as usual.
I've tried a couple of different solutions, such as checking the .csproj file has the form.Designer.cs included, but nothing has worked.
Strangely, I did see this problem earlier in the week, but it fixed itself when I unlocked my computer after returning from a coffee break.
Any suggestions?
I face a similar problem in Visual Studio 2019.
To help others who may have this issue.
The problem is due to the class declaration in the Form1.cs file.
Please ensure public partial class Form1: Form class is the first-class declared in the file. No other class declaration should be on top of this.
As described in this answer: https://stackoverflow.com/a/40243490/8887398
Thanks,
Sankar
I had similar issues in VS2019. I resolved it by using:
Window > Reset Window Layout.
Then double clicked on the Form in the Solution Explorer.
Prior to this, double clicking the form was having no effect.
Weird, after trying for an hour I ended up solving the issue 30 seconds after posting this!
I edited the size property of an item on the form using the properties tab, saved the form, and then reverted the form.cs, form.designer.cs, and form.resx files to the latest source control version.
At this point the form jollily re-appeared.
Edit: FWIW, this didn't work with another form which was exhibiting the same problem.
Edit 2: That other form has now fixed itself after coming back from lunch and unlocking my PC... Might be something to do with how that affects the display - everything shifts over to my right hand monitor when I do that.
Edit 3: OK, now it seems that modifying my display DPI fixes it. On Windows 10 go to System Settings -> Display, and then move the "Change the size of text: 100%" option to say 200%. Once this changes on screen, move it back to 100%.
This seems quite foolproof, although you sometimes have to jimmy it around a lot before it finally works. I know it has worked when I get both a vertical and horizontal scrollbar; the form is then further down the page.
Just go to Form1.cs (Form1 is the name of your form), if you are able to see your source code then press Shift + F7. The form will show up.
I also had a similar issue in VS2019.
My form [Design] was listed in the solution explorer but the code was not listed as a sub-item of that form.
I could access the code by right-clicking on the form in the solution explorer and choosing view code.
What seemed to solve the problem was to close down VS2019 and simply re-open it up.
A Message appeared (with Errors and Warnings) for me which said that the first mentioned class in a cs code file must be the form class. I shifted my form class to the top of the files and everything was fine.
There are actually a few reasons that one might encounter this issue.
At times, it can be due a problem within the VS IDE and the way it incorrectly manages file types and subtypes. It normally does a great job with this "automagically", but it can also make painful and unexpected mistakes.
If you right-mouse-click (RMC) your Project, and unload it (not your solution) you will be able to RMC it again and choose "Edit Project File". Once there, search for your Form name. In my case, I will search for Form1.cs, note the incorrect icon I saw in the Solution Explorer View, and the code describing my form, within the project file:
<...>
<Compile Include="Form1.cs"/>
<...>
Change this declarative statement to the following, adding the "Form" subtype:
<...>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<...>
Save your project file, then RMC on your project name in the Solution Explorer, choose "Reload Project", and you will see the correct icon as expected, and once again be able to use the form in Design mode:
*Note: This issue shouldn't occur with default forms (named Form1, Form2, etc) and even in my case, it happened with a form I named other than the default form name. I used that name in this example, purely for illustrative purposes.
Hopefully, this helps someone.
Wishing you all the best!
I hadn't changed anything that would have broken my form, yet it still wouldn't load when I tried view designer. Restarted VS2019 and it worked after that. Give that a go before you try anything else!
I had the same problem.
My solution was to remove and add again the System.Windows.Forms reference.
Go to Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer ...
Then restart
This seems like it should be pretty simple but I can't seem to make it happen. Lets say I have an existing project with a user control named uc1. I would like to use this user control in another project. I right-click the project name in the solution explorer and select add>existing item, change the drop down to all files and select the files uc1.xaml and uc1.xaml.vb. This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?
Reed's answer is a good architectural one. If you plan on creating a control that you will reuse in many projects then it's best to use a control library.
Your original question is valid in some situations though. Say you have some source code from the Internet that you've unzipped to your drive. This project contains a .XAML file and its linked .vb file that you want to add to a project.
As you seen, the Visual Studio Solution Explorer doesn't link the files when adding with the "Add Item" dialog. I think this is a bug. I find that if I reload the project, the affiliation is added.
Here's a workaround I use. I drag the files from Windows Explorer /File Explorer onto the project in Solution Explorer. That works correctly the first time.
This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?
Normally, you'd add a reference to the other project, and use the UserControl directly.
This allows you to build a single project with your UserControl, and use the resulting assembly (DLL) in multiple projects without duplicating the code.
If you want to reuse your user controls you need to create a new project and choose "Class Library" from the list of available projects. When compiled this class library can easily be used by any number of other projects and solutions simply by adding a reference to compiled DLL created when you build this class library.
Edit: As mentioned in other answer it's "WPF UserControl Library", not simple "Class Library"...
You just need to add the .xaml file and VS should auto add the code behind(nested). I've seen this not work a few times and as #Walt Ritscher said this is probably a bug.
I found simply restarting Visual Studio and reloading my solution worked.
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
I'm just learning WPF. I'm using VS 2008. I've added an Image control to my XAML, and I added a GIF file to the project. If I use the XAML Designer's property panel to set the image's Source property, the drop-down list for the Source property contains the following:
C:\Sample Project;component/pinHorizontal.gif
There are several problems with this:
My project, named "Sample Project," is not in the root of my drive.
Why is ";component" in there?
If I select this value as given, I get the error "Property value is not valid" (yeah, no kidding).
If I go into the XAML source and set the Source property manually, like so:
<Image Name="PinImage" Source="pinHorizontal.gif"/>
The XAML Designer gives me this error:
"The file pinHorizontal.gif is not part of the project or its 'Build Action' property is not set to 'Resource'."
Why is this task so difficult? How do I assign an image source?
Have a read through this article - though be warned it's not particularly light reading :-)
I suspect what you want for your image path is pack://application:,,,/pinHorizontal.gif. if your image is set to a BuildAction of Resource, this will work fine.
Right click on the image file(pinHorizontal.gif) in the SolutionExplorer, Go to properties, here is the 'Build Action' property, you need to set it to 'Resource'. Hope it helps!!
This post is an "and also"... not an answer to the original question.
I just thought I'd document it in case some other poor booger has this problem in future... and googling that error message finds this SO question... so here's a good place to do so.
I've been creating new icons (actually bitmaps) and adding them "on the fly" to my Visual Studio 2008 project (i.e. Add ~ Existing item). The IDE has been reporting file ${filename} is not part of the project or its 'Build Action' property is not set to 'Resource' errors on my XAML page... but my project builds and runs OK... so what gives???
I tried everything I could think of the get visual studio to refresh it's view of the filesystem, to no avail.
Well, I've just dicovered that restarting Visual Studio "refeshes" its cache of filesystem/build-output contents, which makes those annoying non-errors in the IDE go away. So I add a batch of icons, mark them all as Resources ~ Copy if newer, build, and then restart the IDE, and it's all good.
Cheers all. Keith.
In the Solution Explorer, select your project and right click rebuild the solution, and try to add the image again, it should work fine.
--or--
under the Build tab select rebuild the solution, and try to add the image again.
You can use this piece of code in the XAML to load an image from the absolute path without setting nothing. Use DecodePixelWidth or DecodePixelHeight to save application memory.
<Image>
<Image.Source>
<BitmapImage DecodePixelWidth="200" UriSource="C:\image.png" />
</Image.Source>
</Image>
Hope it helps!
I was having the exact same problem. I just manually typed in the location of the file when the Choose image box pops up and that worked for me.
I opened the Choose image box again after I got it to work and noticed that file:/// was now in front of the file location. I know next to nothing about Visual Basic (which is what I'm using) so there may be a good explanation for this, but I don't have it.