469,603 Members | 2,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

Embedding .dll into app

72 64KB
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.


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.
Dec 3 '12 #1
2 7722
465 Expert Mod 256MB
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 :)

Expand|Select|Wrap|Line Numbers
  1. Shared Sub New() '   <--- this must be the name of your main class
  2.     AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf Resolver)
  3. End Sub
  5. Private Shared Function Resolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
  6.     Dim a1 As Assembly = Assembly.GetExecutingAssembly()
  7.     Dim s As Stream = a1.GetManifestResourceStream("Ionic.Zip.dll")
  8.     Dim block As Byte() = New Byte(s.Length - 1) {}
  9.     s.Read(block, 0, block.Length)
  10.     Dim a2 As Assembly = Assembly.Load(block)
  11.     Return a2
  12. 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.
Dec 4 '12 #2
72 64KB
Thank you so much PsychoCoder. A Gentleman and scholar, you are.
Dec 4 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Alicia Haumann | last post: by
2 posts views Thread by Roose | last post: by
reply views Thread by smilechaser | last post: by
1 post views Thread by amit | last post: by
1 post views Thread by Tommy Nordgren | last post: by
1 post views Thread by gavinpaterson | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.