Possible Duplicate:
Embed .net dll in c# .exe
I have been trying to embed a .dll (Specifically Ionic.Zip.dll) into my application, which then compiles a new .exe using CodeDom and requires the Ionic.Zip.dll. I want to be able to distribute my program without any additional .dll's. If there is a DLL in the working directory, the program and the compiled program runs fine. I am not using ILMerge because the compiled program requires the .dll and I can't force the users to get ILMerge. However, if there isn't a .dll I get this error.
Original program won't compile the code with this error
error CS0006: Metadeta file 'Ionic.Zip.dll" could not be found.
Compiled program (Compiled while having the dll in the working directory of the original program)
Description:
Stopped working
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: scrub.exe
Problem Signature 02: 0.0.0.0
Problem Signature 03: 50b0f364
Problem Signature 04: Scrub
Problem Signature 05: 0.0.0.0
Problem Signature 06: 50b0f364
Problem Signature 07: 1
Problem Signature 08: 38
Problem Signature 09: System.IO.FileNotFoundException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Debug Error
Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. The system cannot find the file specified.
Within the CodeDom compiler I have used this code:
Params.ReferencedAssemblies.Add("Ionic.Zip.dll");
To fix this I've tried this and followed it as closely as I could. http://adamthetech.com/2011/06/embed-dll-files-within-an-exe-c-sharp-winforms/
Here's my code within the original application:
public MainWindow()
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string resourceName = new AssemblyName(args.Name).Name + ".dll";
string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
{
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
};
InitializeComponent();
inniZip();
}
private void inniZip()
{
Ionic.Zip.ZipOption test = new Ionic.Zip.ZipOption();
}
I've put similar code in the compiled program source too. I've been stuck on this error for a while now and I just can't seem to figure it out.
Thanks in advance,