My class can't find an interface class which is defined in my project.

I have an interface in my windows forms application. The interface class is named IPAL.vb. Below is a stripped down example,
as I did not include all of the methods of the interface :

Imports System.Data

Namespace TNU.PAL
  Public Interface IPAL
   property ConnectionString() as String

  End Interface

End Namespace

I want to access the above interface in the code behind of one of my windows forms (Shown below). Below is the code where I declare
the interface object IPAL. Now the problem is that my Form1 class below can't access the above interface class, As you can see, I imported the
TNU.PAL interface class below.

When I compile the project code, the compiler gives me the error message "Type IPAL is not defined". So why can't my Form1 class find the interface IPAL defined in IPAL.vb ?

Imports System.Net.Configuration
Imports System.Collection
Imports TNU.PAL

Public Class Form1

 Private Shared MyIPALObj AS IPAL

End Class
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kamal KhaleefaInformation Security SpecialistCommented:
try like this

Private Shared MyIPALObj AS TNU.PAL.IPAL
Jacques Bourgeois (James Burger)PresidentCommented:
There could be other factors affecting the complete namespace.

Call up the Object Browser from the View menu or with Ctrl-Alt-J.

Lookup your interface in there. You can perform a search if needed.

One you have it in the left pane, click on it and look at the bottom of the right pane. The Member of gives you the complete namespace of your interface.
Fernando SotoRetiredCommented:
If the Interface is located in a different project within the same solution did you add a reference to that project from the code you are trying to use that interface in?
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

brgdotnetcontractorAuthor Commented:
Hello Experts. Thank you so much for the help. I took Jacques suggestion, and also weighed what Fernando suggested. The problem is that I am not seeing my interface in the object browser?

Do I somehow need to reference the interface? Up to this point, I just created an interface class, added a namespace to it, and then from the form code used the "Import" statement to reference it? Is there anything else I need to do? Shouldn't the Imports statement by itself reference the Interface class??
Fernando SotoRetiredCommented:
If the Interface is created in a different project then the project you are using it then NO.

If the Interface is in the same project then maybe. The reason for maybe is that if the Interface is in a different folder then where you wish to use it in the Namespace will be different and therefore you may not be using the right Namespace.

Does the solution have multiple projects? If yes is the interface in a different project then where you are using it?

Is the Interface is the same project you are using it in? If yes is it at the same level in the tree in Solution Explorer as the file you are using it in? Or is it in a different folder?
Jacques Bourgeois (James Burger)PresidentCommented:
If you are not seeing it in the object browser, then there is no way that you can use your interface in the code.

The most current cause in such a case is a missing reference, as Fernando suggested. But there are different ways to create a reference, and there is another possibility that has nothing to do with references.

Is your interface file in the same project or in another project?

If it is in the same project, right click on the file in the Solution Explorer and look at the menu. If you have an option to Include the file in the project, then is is not really part of the project. You are seeing the file on the hard disk, but the compiler does not take it into account. In such a case, simply click the Include in project option and you should have solved your problem.

If the interface file is in another project, is this project in your solution of is it already compiled.

If it is already compiled, then you need to reference the compiled dll through the Browse tab of the References tab in the application project Properties window.

If the project containing your interface is in the same solution as the application project, you also need to add a reference. Having 2 projects in the same solution does not automatically make them see each other. If this is your situation, go to the References window, but look in the Solution tab instead of the usual tab. Reference the second project. This will make your application project reference the source code of the project that contains your interface, and you will be able to use it.
Jacques Bourgeois (James Burger)PresidentCommented:

The folder does not influence the namespace. It does in Java, but not in VB. The only things that determine the namespace in VB is the root namespace in the project's properties and namespace instructions in the source code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
It also influence it in C# and if I am not mistaken in VB where a developer raps a class, interface in a different Namespace.
Jacques Bourgeois (James Burger)PresidentCommented:
Sorry to contradict you Fernando, but not in VB. I have interfaces in a few of my projects and always create separate directories for Forms / Classes+Interfaces / Controls. I never had to consider the directories when using either of these.

It's evident if you open the Object Browser. When you open a project in the Browser, it first displays the namespaces available in the project. You never see a directory name in there, no matter the language in use.

There is nothing about that either in the official documentation.

I would appreciate to be pointed to any discussion that would show me that I am wrong however. There are so many little details to learn in that field of ours that it is easy to be wrong, specially when moving from one language to another.
brgdotnetcontractorAuthor Commented:
It was truly an honor to be helped by both of you gentlemen. Very knowledgable!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.