Load DLL from resource with a twist 07-01-2011, 12:55 AM
#1
Suppose your VB.NET application has one DLL and for whatever reason (I was asked this today) you want the DLL embedded into your executable and then when the assemblies need to be loaded extract the DLL from within the executable. Some may ask why? Heck for me it is not wise but search on the web and programmers are look for this. The alternate is to create another AppDomain but that can get into use of Refection and that can make maintainability cumbersome. What might be of interest out of all this is not many know there is an event that gets called when an assembly is missing and you can deal with it, in this case we extract the DLL and load it without the user ever knowing.
The attached VS2008 solution contains two projects, one a simple class library and the other a Windows forms project. In the Windows form project there are two embedded files. Rather than trust me remove them and then build the class library and add the DLL and debug file back into the Windows form project. Now build the Windows form project and then copy the contents of the build folder to another location. Next delete the two class library files and run the Windows project and note that the DLL has been written to the app folder and the code that utilizes the DLL works.
Solution
http://kevininstructor.home.comcast.net/...lyDemo.zip
References
http://visualstudiomagazine.com/articles...omain.aspx
http://msdn.microsoft.com/en-us/library/...ndler.aspx
The attached VS2008 solution contains two projects, one a simple class library and the other a Windows forms project. In the Windows form project there are two embedded files. Rather than trust me remove them and then build the class library and add the DLL and debug file back into the Windows form project. Now build the Windows form project and then copy the contents of the build folder to another location. Next delete the two class library files and run the Windows project and note that the DLL has been written to the app folder and the code that utilizes the DLL works.
Solution
http://kevininstructor.home.comcast.net/...lyDemo.zip
References
http://visualstudiomagazine.com/articles...omain.aspx
http://msdn.microsoft.com/en-us/library/...ndler.aspx
Conflict is inevitable, but combat is optional
My humble self-defense site
Use Option Strict = On when coding with VB.NET
My humble self-defense site
Use Option Strict = On when coding with VB.NET


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)