You have not provided enough detail for me to even guess at what your problem is. However, I can present the pattern I use.
The way I handle embedding dependent assemblies is to use the AssemblyResolve
event. You wire up the event once and then if the CLR cannot find the assembly on disk it will raise this event. When the event is raised then you extract the assembly bits from the resource manifest and call Assembly.Load
.
Here is what the code might look like.
internal class AssemblyResolver
{
public static void Register()
{
AppDomain.CurrentDomain.AssemblyResolve +=
(sender, args) =>
{
var an = new AssemblyName(args.Name);
if (an.Name == "YourAssembly")
{
string resourcepath = "YourNamespace.YourAssembly.dll";
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcepath);
if (stream != null)
{
using (stream)
{
byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
return Assembly.Load(data);
}
}
}
return null;
}
}
}
And then it can be used like this.
public static void Main()
{
// Do not use any types from the dependent assembly yet.
AssemblyResolver.Register();
// Now you can use types from the dependent assembly!
}
I have used this pattern successfully for many years. There are a few caveats, but for the most part it works well. It is certainly a lot better than using the ILMerge tool.