1

I like to connect the DLL (which contains namespace Chart) and call the subroutine public Simple() from the second class (namespace WinApp2). There is a error:

couldn't find type or namespace name Simple

Although I consider a reference and put using Chart and created a instance in the second namespace.

namespace Chart
{
    public partial class Simple : Form
    {
        Manage _mProject;
        public Simple()
        {
            InitializeComponent();
            _mProject = new Manage();
            _mProject.Add(new Task() { Name = "New Task" });
            _mChart.Init(_mProject);
        }
    }
}

using Chart;
namespace WinApp2
{
    public partial class Form4 : Form
    {
        Form2 fh;
        public Form4(Form2 aufrufer)
        {
          fh = aufrufer;
          InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
          var instance = new Simple();   (error !!!)
          instance.Simple();
        }
    }
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
joe
  • 61
  • 2
  • 6
  • 4
    Are you sure the error appears on `new Simple` instead of `instance.Simple`? The latter won´t compile as `Simple()` is a constructor, not a method. – MakePeaceGreatAgain Mar 01 '16 at 22:16
  • MegaTron, I connected the DLL source file in the VS project file .. – joe Mar 01 '16 at 22:42
  • HimBromBeere, Yes it's the var instance = new Simple(); line which bring the error .. – joe Mar 01 '16 at 22:43
  • 1
    @joe try to remove line `instance.Simple();` and check again – Roman Marusyk Mar 01 '16 at 23:01
  • MegTron, No difference. It's still idicating and error that Type or Namespace name "Simple" couldn't be found (missing a using-Directive or a Assembly reference?). – joe Mar 02 '16 at 09:08
  • Or is the issue related to the partial class definition ? – joe Mar 02 '16 at 09:49

1 Answers1

1

What do you mean by "consider a reference and put using Chart" ? Did you actually include the dll in References section, or did you put using Chart and think that will reference the relevant dll?

The proper steps are:

  • Right click References section in VS
  • Choose Add Reference
  • Browse to location of relevant dll, choose OK

Another cause may be that Chart is a defined class in System.Web.DataVisualization.dll, so VS is confused. Try changing your Chart namespace to something else, e.g., MyChart

Hope this helps..

JustAPup
  • 1,720
  • 12
  • 19
  • Minh, I followed your steps, but it still indicates the error CS0246: Type or Namespace name "Simple" couldn't be found (missing a using-Directive or a Assembly reference?). Obviously the using Chart was correctly be found so that must be any refereence. – joe Mar 01 '16 at 22:40
  • Minh, the line shows no problems now, which indicates that obviously the DLL must correctly referenced (or not?). But the second line has now an error that Simple() has no definition for Simple();. Is it a problem if the class has the same name than the subroutine .. ? – joe Mar 07 '16 at 17:14
  • You can't call instance.Simple() because Simple is not a method, but rather, it's a default constructor, called when you instantiate the class, as @HimBromBeere has correctly pointed out – JustAPup Mar 07 '16 at 17:36
  • Just delete that instance.Simple() line, and everything should work as expected – JustAPup Mar 07 '16 at 18:05
  • Minh, Ok I got it now what you and HimBromBeere mentioned about the constructor. Thanks. – joe Mar 07 '16 at 18:43