C# component do not refresh when source code updated - c#

I have a solution with many projects. One project contain few custom components. One of these components is used to display a title on an image. We can change the color of the background and many other things.
The problem is IF I decide to change the default color of the background of the component or change the position of the text, thoses change won't reflect in all other projects of the solution where the component is used. I have compilent the project of the component and all other projects Reference the component by the Project.
For the moment, what I have to do is to take off the component from the other project one by one and to add it back, then all is fine. Do you have a quick way to do it?
UPDATE
I have added a CheckBox inside that component and it seems that the checkbox is everywhere! Fine! But when a property has a some tag that let the component to change (example like the Background color) it doesn't change the "default" value but instead put the old value as a changed value in the property. So, I see the old value setted like if I add manually changed the color in the Properties panel when I haven't...
UPDATE 2
alt text http://img517.imageshack.us/img517/9112/oldonenewoneei0.png
Update 3:
This problem is still here. Just to let people know that I am still curious to find a way.
I have tried few of your suggestions.
If I clean all the solution and build only the project that has the Custom control then I build the solution. Nothing change (To test it, I have change the color of the component to Yellow. Nothing change : fail.
If I remove the reference and add it back to the project and then rebuild the solution. I can see the old color in the designer : fail.
I have updated the question with more information and an image (above) for those who want to try to help me.
As you can see, the old "compile" of the component show the Yellow background but when I insert a new component (from the Left Tool bar in Visual Studio) I can have the new component with the supposed WHITE background...

This is most likely due to references.
Your other projects probably copy in a reference to your component project. You'll have to rebuild these other projects for them to re-copy in the referenced component project, if it has changed. It is only updated at build time.
You can somewhat get around this by having them part of the same solution. In that case, you can set up your project dependencies correctly and it should handle things for you mostly automatically. But having everything in the same solution isn't always the right thing to do.
If you already have them part of the same solution or it's not a references problem, it might be due to component serialization. We've run into this quirk a lot when doing custom control development.

My guess is that the designer is smart and remembers the settings for the component as you have it in the designer and thus sees it as the default.

This doesn't sound usual. Right clicking on the solution and hitting "Clean Solution" might help (it will delete all dlls and executables from each project's bin directory, which forces fresh builds to occur)
You might also want to check your build order sequence.

I work on a project that has a similar problem, I have found that if you touch the .NET config file or assembly information file (depending on your project type). The other projects will then reflect the component change...
I'm not sure why this happens, but this is how I overcome it...
Recently I have switch to building everything via Nant, and that takes care of the problem altogether.

Sometimes the Visual Designer serialize all your properties in the code-behind, even if they have the default value.
If your component have a default backcolor of Red, and you change the default backcolor to Blue, the components that use your component will change it back to Red.

Related

Why am I getting design-time error?

I have a Winforms project with a FormMain.cs. I can build the project without error and it functions as a start up project.
However, when I click on FormMain.cs to access the design view, I see the following design-time error list:
Could not find type
'UserControlsTabbed.UserControlTabPanel'.
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 using settings for
your current platform or Any CPU.
and
The variable 'userControlTabPanel1' is either undeclared or was
never assigned.
I certainly recall using the design view of FormMain.cs. I recall placing userControlTabPanel1 in a tableLayoutPanel cell within FormMain.cs. I did not have any design-view errors at that time. That was perhaps 100-150 version ago in my code repository. I have not had any need to access the design view of FormMain.cs until now.
The second error message is especially confusing. Opening FormMain.Designer.cs I see that the auto-generated code contains both the declaration and assignment.
I am confused as to why the winforms application executes without issue but the design-view has errors. Any assistance would be appreciated.
There are a number of issues causing this problem.
Project Platform target must be set to x86.
TableLayoutPanel do not support visual inheritance. Instead, use containers that support visual inheritance such as GroupBox, Panel, SplitContainer, or TabControl.
Inheriting usercontrols that do not conform to 1. and 2. of this list causes errors in the design-view.
By implementing the above 3 observations in my solution I was able to successfully remove the Design-time errors.

Can't select controls on my form

This has started happening recently (not too sure what caused the change unfortunately), but I can no longer select controls on my form. My reading on this has uncovered some possible explanations including:
You're running your program in debug mode
Your form is derived from another class where everything is private
Your controls are "locked".
For (1), no, it's definitely not running and for (2) my form is derived from DevComponents.DotNetBar.RibbonForm. For (3), no, they're not "locked" (I tried locking and then unlocking, in case some state was stuck in the designer, but no dice). The controls are on my form, not the base class form and the instances aren't private (I deliberately made them public just to test this one) and they were working fine before.
So, what can I do? I can select a control, like a ComboBox, from the Properties window drop-down list, change its properties and so on. But when I choose it nothing gets selected in the designer. I can select the form itself (by its border) and resize it in the designer. I can add a new control, like a label, and interact with it fine in the designer, so this is something that's happened to my existing controls.
I'm sure it's either something spectacularly dumb, or Visual Studio 2012 is on the wind-up.
Anybody?
Edit: Zipped the solution up and brought it home. Cleaned and rebuilt and it's working fine in the designer. I guess there's an issue with my install at work, somehow.
The problem can occur when a new version of DevComponents.DotNetBar is installed and the old version is still referenced from a separate library folder.
The app and all DotNetBar referenced dlls should be re-referenced to the latest version.
Well, I kind-of solved the problem, although I don't know what the actual cause was. In my program I'm referencing devcomponents.dotnetbar dll. I removed the reference and then re-added it, rebuilt the program and now everything's working in the designer as it should.
This problem's main reason is because of older versions of components being used in a project and a newer version of the component has been installed on the machine. 9 times out of 10, the project is still pointed to the component in the GAC. Remove the reference to the component and re-add it from the newly installed component's location and all should work fine.
I had the same issue with DotnetBar, resolved it by adding the reference DevComponents.DotNetBar.Design.DLL in the project
Just right-click the form and uncheck Lock Controls.
Resetting the Toolbox (Right click inside Toolbox) and then "reinstalling" the new toolbars did the trick for me. Seems to be a bug in Visual Studio.
I had the same situation but Closing and Re-Opening my project solved the problem
I had the same issue after moving a project to another PC. I didn't install DotNetBar on the new machine and just copied the DevComponents.DotNetBar.dll. I resolved it by also copying DevComponents.DotNetBar.Design.dll (contained in the old machine's DotNetBar installation directory) to the new machine and referencing it in the project.
The general issue is using references that no longer exist. For me, I had several versions of Infragistics controls and uninstalled all but the latest version. At least one of my references pointed to a DLL that didn't exist. Therefore, the seeming removal and re-adding essentially pointed the references to the correct (or present) DLLs.
Also, one of the symptoms of this problem is that the labels for the controls appears in a window below the dialog/form.
To get this working for me I ended up having to add the references to the designer for the different controls: SuperGrid.Design and DotNetBar.Design
I had that problem, and it was caused after I wrongfully played around with my "using" and "namespaces" in a blind attempt to get rid of an error. I saved each .cs file one by one and then closed VS and re-opened it. Presto, the little locks vanished.
I had the same issue, you can ctrl+a to select all, then move the controls to somewhere, doesn't matter where. Now you will be able to select them again seperately.
I got this problem by dragging a tab down so i could see two codes at the same time.
I know this is an old post, but in case it helps someone else, my version of this problem was an inability to select controls on a tab page. Sending the tab page to the back didn't help. But I found I could get the controls highlighted by selecting them in the properties box and then placing the mouse over the control sizing arrows and right clicking, I could then bring the controls forward.
Just Closing the current Soln and Opening again solves this problem,
This might have caused because of some hidden selections in other forms!
For me the issue was only with "Send to Back" and "Bring to Front"
I did Control+A then deselected every other control, then right clicked on the controls i was not able to see before and just clicked "Bring To Front".
For me the issue happened because i removed those controls from Group Box.
Visual Studio 2019, I close the form, and any files currently open that are associated with that form (.cs .rex) and then reopen them. This solved my 'not being able to select a control' problem. I find this problem occurs occasionally, and is a bit of a nuisance, but this simple fix always seems to work for me.
I ran into another variation on this theme. I'd placed Infragistics controls into a lib folder. The project would still compile/run, but for the controls to be selectable in the editor the project must reference the original installed controls. See Cannot select Infragistics controls in WinForms designer for more details.

Visual studio shows endless messages "Code generation for property 'valueMember' failed."

After several days of happily hacking away on this C# app using Visual Studio 2008, I get struck by a barrage of error dialogs showing:
Code generation for property 'valueMember' failed.
Error was: 'Object reference not set to an instance of an object.'
This happens now often when I make a tiny change in the designer, e.g. shift a control a few pixels, and then try to save. Several such error dialogs appear each second, keeping me busy cancelling all those by hammering the Enter key while trying to get alt-F4 to get VS to close.
Eventually I do get VS to close and to save the changes I made. After restarting VS, I do "clean" on the entire project, then "build" and everything works fine, the app runs fine, no problems.
Until I make another slight change in the form designer.
I don't know about any property valueMember in my app.
This makes me crazy, it is a real showstopper for my project. Any help is appreciated.
Try to Close and reopen the Visual Studio. maybe it seem silly, but it works!!
You can debug the designer using another visual studio and attach to process. If you got exception it should be easy to find it that way.
In general when openning the designer the constructor and of course initializeComponent is running.
As this is happening at design time, it is likely that you have a custom control which requires a parameter or other value which does not have a default.
When in design view in Visual Studio; a control instance is created to render it on the visual editor, but if the control requires a property to be set before it can be rendered, it will result in an error.
Can you check that all custom controls have default values, and anything referenced in the constructor that cannot have a default is wrapped by DesignMode property - see http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx.
Similiar to #Chanipoz's answer (close/re-open) my component-rich/user-controls-everywhere forms app started to compile happily after I closed down the main form designer window.
I've had this code stack for years and have never seen the error until today. Not sure where it's coming from. But, something today about having the form open in the designer made everything unhappy. Simply closing it off of the screen made it all go smooth.
Use another instance of Visual Studio to attach to the first instance of visual studio.
Go to Debug-> Attach To Process and look for the devenv.exe process. Since you'll have two devenv.exe processes running you'll probably want to pick the one with the lower ID, that's usually the first instance of visual studio that was run.
I had to face this problem. As I have found the solution below
I am facing this issue in my customized control.
we need to implement like this
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public MyCustomclass _Prperty { get; set; }
I had to face this problem. As I have not found the solution (much inheritance), I can tell:
.SuspendLayout() and .ResumeLayout() may be missing in code or one of them. The same is with .BeginInit() and .EndInit(). It is expected between them, that there will be = new ... and some settings for properties. Maybe someone facing this problem would find the solution with this information.
The problem is missing initialization code for a public property on the control. This will be added for you when you add the control to the designer, but if you replace a control with a derived control, or update the component, then the designer does not know how to deal with this.
If you have a control (wincontrol) with a public property PropertyA, and you add it to a form (myForm), then the designer will add all the necessary initialization for properties into myForm.Designer.cs. Something like;
Wincontrol1.PropertyA = new List<widget>();
It is not uncommon to need to modify a control slightly, lets say we have a new control MyWinControl
public partial class MyWinControl : WinControl
{
public List<wodget> PropertyDer1;
protected List<wodget> PropertyDer2;
}
If you sub this new control for the old control in myForm.Designer.cs, then you may well encounter this issue. The reason is that PropertyDer1 has no initialization in the winforms designer. PropertyDer2 won't cause any issues because it is protected. Similarly if you had a custom component and you add a new public property after the component has been added to a form.
If however, you deleted the instance of WinControl on the form, and dragged an instance of the MyWinControl onto the form instead, the proper initialization would occur and you would not see the error. The designer will have created the new control like this
Wincontrol1.PropertyA = new List<widget>();
Wincontrol1.PropertyDer1= new List<wodget>();
There are two easy solutions that do not require hiding the property from the designer.
1. If the property doesn't need to be public, give it the right modifier
2. If the property does need to be public, then just edit the code in the myForm.Designer.cs as in the code above to add the missing initializer
If could be of help I just detected a case that brings that same error message, impossible to take away :
I am developing an application in French, and I had to create a ToolStripMenuItem with an accented word in it like "annulées".
The system generated a menu item like "annuléesToolStripMenuItem" and the accent is the culprit.
Enough to delete the item, create it again in English and the just change the Text property of the menu item.
Hope it will be of some help.

Why does my class suddenly have a 'designer'?

I just finished adding and removing different database models (I was trying to figure out which one I should be using for this project) then after playing around for a while I noticed one of my classes's icon changed from what is shows beside my Calculations.cs class in the first image to the Balance.cs icon.
The Balance.cs now has this Designer component so when I double click on it I see my second screen shot. This seems to be allowing me to add components from the toolbox to my class. There are actually two classes within my Balance.cs. This Designer thing is only affecting/interacting with one of them (it inherits from SerialPort).
I don't really know what changed or what I did to make this happen and ctrl+z is not being my friend here. How do I change Balance.cs back to a regular class with no designer component?
Thanks
If any of the classes in a source file inherit - either directly or indirectly - from System.ComponentModel.Component (such as SerialPort), Visual Studio will provide design-time support to you. This is sometimes unwanted behaviour, and you can safely ignore it in most cases.
If it really bothers you, you can decorate your class with the [DesignerCategory] attribute (set the category to an empty string).

Weird XAML problem

I am creating a XAML based application and running into a funky problem that isn't making any sense to me at all.
The problem: I make changes on my XAML, very minor ones such as changing the text content on my buttons. The design field reflects these changes as they should. However, when I run the project, the changes do not render themselves. The same window renders itself but the text content that was altered in the buttons do not change itself.
The problem is a microcosm of the bigger problem, which is that any kind of back end changes I make such as the data binding do not reflect themselves when the app is executed.
I am still exploring where i could be going wrong, but if anyone has any leads on this, I will much appreciate it!!!!
Thanks,
Parijat Kalia
Delete your pdb files from bin/debug and rebuild your application.
As I understand it, Visual Studio (the compiler, more accurately) sometimes does not detect small changes made to the code. Doing a Clean or a Rebuild (which, IIRC, is a Clean & Build) should force VS to recompile all files without needing to check for changes.
The logic behing the changes detection is to speed up compilation, compiling only the changed files.

Categories

Resources