0

I have to call an external .Net Framework assembly that required to be consumed in different projects (Console, Desktop and Web Applications). In order to avoid adding external assembly, I have created a class library project and wrap external assembly calls in an Friend class and called that class from a public class that is exposed to outside world. But When I run my project, it expect dll to be included in Console application as well.

I was expecting that friend classes are not accessible to outside world, so assemblies consumed are not required to outside world. But as soon as I inherit my friend class from an outside assembly, Console application call of MyCalling.UserLogin blows up. I also tried making Friend class Private that does not work as well.

Public Class MyCaller
    Public Shared Function UserLogin(ByVal username As String, ByVal password As String) As Boolean
        Return MyFunctions.Instance.UserLogin(username, password)
    End Function
End Class

Imports ExternalLibrary

Friend Class MyFunctions
        Inherits ExternalClass

        Private Shared instanceField As MyFunctions = Nothing
        Friend Shared ReadOnly Property Instance As MyFunctions
            Get
                If instanceField Is Nothing Then
                    instanceField = New MyFunctions()
                End If
                Return instanceField
            End Get
        End Property

        Public Function UserLogin(ByVal username As String, ByVal password As String) As Boolean
            Return False
        End Function
End Class

I try to avoid adding external assemblies to multiple projects, and expect my code to not expect the assembly that's references in a friend class, but everytime I run the project it blows-up

  • 1
    The actual JIT compile-able and executable code of that external assembly still only exists inside that external assembly, it doesn't get pulled inside your class library, so that external assembly is still required at runtime, yes, when it gets to the point of that code needing to compile and run. – Damien_The_Unbeliever Aug 31 '23 at 13:08
  • 1
    @Damien_The_Unbeliever, It doesn't make much sense to me to add the External.dll in Web and Desktop, if it already included to a referred class library – Farhan Iqbal Aug 31 '23 at 13:11
  • Do you have the source code for the external assembly? If not, then you will need to include the DLL. – SSS Sep 01 '23 at 06:38
  • If that external "referred" class library has the assembly references, then just referencing that new referenced class library in any ohter new project should in theory build time then pull in the required .dll's. I suspect we are missing a big detail here. Are you talking about including multiple projects into one, or are we talking about a separate class that references those other assemblies, and then you now using + refencing that new class. As noted, a simple reference to that new external class should then cause any and all .dll's to be pulled (tossed) into the bin folder at build time. – Albert D. Kallal Sep 01 '23 at 18:44
  • The way I understand Friend directive, it only makes variables/functions expose themselves to the class which utilized them. Try making it Public to be able to Inherit – UnhandledException-InvalidChar Sep 02 '23 at 09:05

0 Answers0