Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB Cannot access class from different project, same solution

I am working in VB for Visual Studio and have a class in a project that needs to declare a variable as a class in another project. For visualization: Solution A contains Project1 and Project2. In a class in Project1 I need to declare a variable as a classname of Project2. The class I need to access is a Friend class and I know I have to do something involving Imports, declarations, references, and maybe class libraries. If anyone can spell this out for me I'd appreciate it. I'm new to VB.

like image 270
user3195786 Avatar asked Nov 17 '25 16:11

user3195786


1 Answers

A friend class can only be accessed from the same assembly, unless you muck around with the InternalsVisibleTo attribute. If these assemblies are not declared as "Friend Assemblies" you need to make the class public. Given you're beginning to learn VB.NET I'd stick with making the class public.

You also need to add a project reference from Project1 to Project2. In the solution explorer right click "References" and choose Add Reference in the dialog that pops open, select "Solution"/"Project" and select Project2.

like image 160
jessehouwing Avatar answered Nov 20 '25 12:11

jessehouwing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!