Loading an embedded assembly from another embedded assembly into the executing assembly

I have a custom code library (.dll) where I store controls and shared procedures that I’ve written. Two of the controls in my library reference a 3rd party .net assembly (.dll).
      Using my custom library, I have another assembly (.exe). Currently I have my custom library added as a resource to my exe, and I load it using the AssemblyResolve event as shown below:
    Public Sub New() ‘The constructor for the main form in my exe

        AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf Domain_AssembilyResolve

        ' This call is required by the designer.

        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Private Function Domain_AssembilyResolve(sender As Object, args As System.ResolveEventArgs) As System.Reflection.Assembly
        If InStr(args.Name, "MyLibrary") Then Return Assembly.Load(My.Resources.MyLibrary)
        Return Nothing
    End Function

Open in new window

     The problem comes in here. I want to load the 3rd party dll along with mine, without having to add it as a resource to my main executable. In other words, I want to embed the 3rd party dll in my custom library import them both.
      The reason for this is that if I don’t do it this way, I’ll have to embed the 3rd party dll in any project which uses my dll. This isn’t crustal just convenient. Can it be done?
Who is Participating?
BROOKLYN1950Connect With a Mentor Author Commented:
I figured out that as long as I don't call any classes that reference the 3rd party DLL it doesn't have to be loaded (which should have been obvious), so I only need to include it in projects which reference those classes. This is something I can live with.

As for 'Cross-domain proxies', they seem a little bit over my head at the moment, so unless someone else has some extremely simple idea (which I doubt) I think I'll just drop this one.
Bob LearnedCommented:
This sounds like a cross-domain proxy is where you should look:

Fast Marshaling for Cross-AppDomain Proxies
BROOKLYN1950Author Commented:
I'm not very familiar with AppDomains (though I bet I will be after this), so I can't tell if this is what I need or not. Either way, the code there is closed-source so I wouldn't be able to use it anyway.
Bob LearnedCommented:
That CodeProject article was meant to highlight the concept of cross-domain calls.

Here is blog entry that describes the concept:

Executing Code in Another AppDomain

"Be sure to not pass any Type/Assembly/etc. instances (besides your MarshalByRefObject type) back to the original appdomain. If you do, it will cause those assemblies to be loaded into the original appdomain."

If you need to export any types, then cross-AppDomain would not be a good choice.
BROOKLYN1950Author Commented:
See the post as to why it is the answer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.