>I have a class which I only want to expose access from its own DLL. However, another class from this DLL is creating an instance of that class. Then, from that instance, that class exposes a method or a property of the class that should not be available outside the DLL.
>
>So, lets say a class is creating an instance of the other class as:
>
>
> Public oUpload As Framework.Upload = New Framework.Upload(oProcess)
>
>
>And, this class can expose oUpload to the application as it is public. So, the application can then do things like this:
>
>
> ' Assign the Excel file
> loImport.cSource = oUpload.cFile
>
>
>So, at this point, the Upload class is defined Public and the other class creating an instance of it is declaring oUpload as Public. Thus, the application can gain access to the Upload methods and properties which are public.
>
>Having said that, it means the application can create an instance of the Upload class. This is what I do not want. If I put Friend for the class declaration, this will allow the other class to create an instance of it but will not allow the other class to declare oUpload as Public.
>
>Is there a way to negotiate with that need?
If your only concern is to prevent instantiation of the class outside of its own assembly then mark the constructor as Friend:
Namespace Framework
Public Class Upload
Friend Sub New()
End Sub
End Class
Public Class PublicClass
Public oUpload As New Upload()
End Class
End Namespace
If there are members of Upload that you also do not want to expose outside of the assembly then just mark those Friend as well.....