I have a question related to the error on the title. Im working with c# and Visual Studio 2010.
I have a form declared as \"public class FormularioGeneral : Form\",
I am working with WPF inside of Windows Forms.
I hosted my WPF User Control in a Windows Forms Element Host. Due to that when InitializeComponent() got called I executed Code before reaching the InitializeComponent() of my WPF control. Tricky.
So I moved it out of my constructor, Clean Build, Rebuild, Restart VS and everything works as expected. Finally.
In my case, I added a third party control in my Toolbar(via a .dll file), and draw one of it in my form. And for some reason, my Toolbar clean this third party control out of the general group(I added it in the general group), so VS cannot find this control. Here is what I done to slove this problem:
Redraw the control if neccessary.
So, I have had the same problem in the past, for fix I did the following:
Thanks a lot to Marshall Belew!
About the variables, can you simply initialize them in the declaration? I think that would suffice, even if you change the value later. From what I'm seeing, the compiler is unable to check whether you have initialized them or not because it's not directly on the constructor code, it's being done on a virtual method which will evaluate only at runtime.
So, instead of:
protected Color m_VariableName;
public Color VariableName
{
get { return m_VariableName; }
set { }
}
Do:
protected Color m_VariableName = Color.White; // Or null
public Color VariableName
{
get { return m_VariableName; }
set { }
}
And a comment: you should avoid virtual calls in the constructor, which can lead to obscure errors in your application. Check it here.