Embedding .dll into app

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maylortaylor
    New Member
    • Nov 2012
    • 72

    Embedding .dll into app

    I have a console app that basically zips files using Ionic.Zip. I just built the exe file and it works just fine while it is in the 'Release' folder that it was built in. However, whenever i move the exe file from that folder it fails b/c the program is looking for the Ionic.Zip.dll file.

    I found on Ionic's website a thread that explains how to embedd the dll file into the exe so you don't need to have the Ionic.Zip.dll file in the same folder as the exe for the program to execute. However, the method they use is a bit more advanced than I am used to.

    So the question is...can anyone give me guidance on doing the steps listed in the last paragraphs linked below.



    ---EDIT----
    Ok, i figured out the first part (Project > Add Existing Item...; then finding the file in the 'Solution Explorer' and changing the Build Action to "Embedded Resource)

    But now my issue is figuring out the VB code to actually implement this change. They have C# on the above link and i'm absolutely awful at translating.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Normally I wouldnt just do the translation for you but I know you've put forth quite a bit of effort on this so here's the C# code translated to VB.NET for you :)

    Code:
    Shared Sub New() '   <--- this must be the name of your main class
    	AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf Resolver)
    End Sub
    
    Private Shared Function Resolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
    	Dim a1 As Assembly = Assembly.GetExecutingAssembly()
    	Dim s As Stream = a1.GetManifestResourceStream("Ionic.Zip.dll")
    	Dim block As Byte() = New Byte(s.Length - 1) {}
    	s.Read(block, 0, block.Length)
    	Dim a2 As Assembly = Assembly.Load(block)
    	Return a2
    End Function
    For future reference you can download and install an IDE called SharpDevelop (or #Develop) and it has a built-in code converter you can use.

    Comment

    • maylortaylor
      New Member
      • Nov 2012
      • 72

      #3
      Thank you so much PsychoCoder. A Gentleman and scholar, you are.

      Comment

      Working...