We use ILMerge to merge a lot of assemblies to a single one for simpler deployment. The result is not compatible with Mono and has issues with WPF.
“… ILMerge works only on Windows-based platforms. It does not yet support Rotor or Mono … ILMerge is not able to merge WPF assemblies.”
ILMerge – Microsoft Research
On the ILMerge site there is a link to what they call “A Great Alternative to using ILMerge”: CLR via C#, Third Edition. The idea is to add all referenced assemblies as embedded resources and load them when they are needed. Here are my tips how to apply this to your project.
First I added all referenced assemblies my WPF application had. To keep things organized I added them to a folder called Resources. Next select all assemblies under Resources in the Solution Explorer and select “Embedded Resource” for the Build Action in the Properties window. This made my program around 10Mb in size after compilation.
In the constructor of the App.xaml.cs class add the AssemblyResolve eventhandler:
public App() : base()
{
AppDomain.CurrentDomain.AssemblyResolve += (s, a) =>
{
var name = new System.Reflection.AssemblyName(a.Name).Name;
var resourceName = string.Format("YOUR_NAMESPACE_HERE.Resources.{0}.dll", name);
using (var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourceName))
{
if (stream != null)
{
var assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return System.Reflection.Assembly.Load(assemblyData);
}
else return null;
}
};
}
Notice the YOUR_NAMESPACE_HERE and the Resources after that. The assemblies are in the Resources folder and that will be part of the name of the embedded resource.
To be able to debug missing assemblies in the startup of your application, register an DispatcherUnhandledException handler and start a Debugger from there:
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// Debugger will break on the line below
System.Diagnostics.Debugger.Launch();
// inspect the e.Exception
}
This will present you with an Just-In-Time Debugger dialog when an exception occurs and you can find out what happend.

Otherwise the application just crashes and you’ll see “FileNotFoundException” in the event viewer.