By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Embedding .dll into app

P: 72
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
Share this Question
Share on Google+
2 Replies

Expert Mod 100+
P: 465
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

P: 72
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.