Drivers Category

Drivers Update
Drivers

Net embed dll in exe build

Version: 42.41.26
Date: 05 March 2016
Filesize: 0.461 MB
Operating system: Windows XP, Visa, Windows 7,8,10 (32 & 64 bits)

Download Now

Hello. I've used ILMerge in the past when I needed to include the DLL's my assemblies depended on and only have to distribute a single exe file. Jeffrey Richter recently posted some c code that allows you to embed the DLL's and load them from a byte array as embedded resources. I wonder if anyone here has done this in VB.net yet?( Without a bunch of off topic discussion about if this is legal to do ) I've tried to understand how you would do this in VB.net, but I'm kinda at a loss. Here is the original link Here's the code sample he gives(in c I'm just not sure how to handle the event in VB.net since among many things the sub main is semi hidden and my lack of the appdomain knowledge Code: App Domain. Current Domain. Assembly Resolve += (sender, args) => String resource Name = Assembly Loading And Reflection. + new Assembly Name(args. Name). Name +.dll ; using (var stream = Assembly. Get Executing Assembly. Get Manifest Resource Stream(resource Name) Byte[] assembly Data = new Byte[stream. Length]; stream. Read(assembly Data, 0, assembly Data. Length return Assembly. Load(assembly Data ; A rough conversion to vb.net Code: App Domain. Current Domain. Assembly Resolve += Function(sender, args) Dim resource Name As [ String] = Assembly Loading And Reflection. + New Assembly Name(args. Name). Name if (assembly Name. Ends With(.resources ) return null; string dll Name = assembly Name +.dll ; string dll Full Path = Path. Combine( Get My Application Specific Path dll Name using ( Stream s = Assembly. Get Entry Assembly. Get Manifest Resource Stream(typeof( Program). Namespace +. Resources. + dll Name) byte[] data = new byte[stream. Length]; s. Read(data, 0, data. Length /or just byte[] data = new Binary Reader(s). Read Bytes(int)s. Length File. Write All Bytes(dll Full Path, data return Assembly. Load From(dll Full Path ; The key here is to write the bytes to a file and load from its location. To avoid chicken and egg problem, you have to ensure you declare the handler before accessing assembly and that you do not access the assembly members (or instantiate anything that has to deal with the assembly) inside the loading (assembly resolving) part. Also take care to ensure Get My Application Specific Path is not any temp directory since temp files could be.
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 Shared Sub New  ' <- this must be the name of your main class  Add Handler App Domain. Current Domain. Assembly Resolve, New Resolve Event Handler( Address Of Resolver) End Sub Private Shared Function Resolver(sender As Object, args As Resolve Event Args) As System. Reflection. Assembly  Dim a1 As Assembly = Assembly. Get Executing Assembly  Dim s As Stream = a1. Get Manifest Resource Stream( 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 Sharp Develop (or Develop) and it has a built-in code converter you can use.

© 2012-2016 cosratasu.5v.pl