I have a problem with this code. You can find all classes here.
If I launch the application and I want open a new Form i receive this error:
NullReferenceException : Object reference not set to an instance of an object.
The main application is set to isMDIcontainer = true;
Now I received the error in this part of code:
private void PluginClick(object sender, EventArgs e)
{
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
Plugin.PluginForm form = ((PluginInfo)menu.Tag).CreateInstance();
form.MdiParent = this; // Here is thrown the error
form.Show();
}
Plugin.PluginForm is only an Extended Form. This is the CreateIstance() method:
public PluginForm CreateInstance()
{
if (!File.Exists(FileName))
return null;
Assembly ass = Assembly.LoadFile(FileName);
foreach (Type type in ass.GetTypes())
{
if (type.BaseType == typeof(PluginForm))
{
return (PluginForm)Activator.CreateInstance(type);
}
}
return null;
}
In the same sebsite someone says that this error could may be resolved in this way:
You must declare property system.window.form parentForm in interface
but I didn’t understand how.
Chances are good that
CreateInstanceis returning anullbecause theFileNameis wrong (incorrect filename or path).The result of it returning a
nullis that theformvariable isnulland any member access on it (as inform.MdiParentwill result in aNullReferenceException.Make sure that the filename is correct and that the file exists in the path it is searched on.