Link to home
Start Free TrialLog in
Avatar of resourcesys
resourcesys

asked on

Make friend class visible to another assembly

Hi all,

I have written a test class in an assembly. It is a friend class and I would like it to be visible to another assembly. The class is as follows:


Imports System.Runtime.CompilerServices

<Assembly: InternalsVisibleTo("T01_BLL")>
Friend Class Class1

    Public Function HelloWorld() As String

        Return "Hello World"

    End Function

End Class

the problem I have is that when I add another class to the assembly, it is also visible to the other assembly.

Is there a way to get the single class to be visible and not all classes of the assembly?

Any help is greatly appreciated.

Thanks.
Avatar of pedros7
pedros7
Flag of United Kingdom of Great Britain and Northern Ireland image

You'll need to set the class as public.

That should work. The keywords Private, Friend and Public are the following:
Private – within the same module, class, or structure.
Friend – within the same assembly.
Public – anywhere in the same project, from other projects that reference the project, and from any assembly built from the project. In other words, any code that can find it.

Regards
Use the keywords above per class accordingly:
Public Class Class 1{}
Private Class Class 2{}

Regards
Sorry, just re-read:

If you want to restrict the view to another asembly only, there are a few alternatives:
. set the other class members as private... but that means they are also private to each other within the same assembly

. the assembly attribute InternalsVisibleToAttribute can be used multiple times, hence, using a 3 assembly structure, you could have: AssemblyA, AssemblyB and AssemblyC
AssemblyB would include the common classes (as in your example above), and with the InternalsVisibleToAttribute set twice to allow visibility to AssemblyA and AssemblyC (where you'd put the rest of your classes).

Hope this helps.
Avatar of resourcesys
resourcesys

ASKER

Hi pedros7,

Thank you for your responses.

The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.

The website would interect with the BLL and the BLL would interact with the DAL.

I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.

I think that would would work.

I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.
Sorry, the last message should read as:

Hi pedros7,

Thank you for your responses.

The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.

The website would interect with the BLL and the BLL would interact with the DAL.

I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.

I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.

I think that would would work.
ASKER CERTIFIED SOLUTION
Avatar of pedros7
pedros7
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question answered
Thanks pedros7.