Skip to content

Instantly share code, notes, and snippets.

@YBogomolov
Created December 23, 2013 08:32
Show Gist options
  • Save YBogomolov/8093485 to your computer and use it in GitHub Desktop.
Save YBogomolov/8093485 to your computer and use it in GitHub Desktop.
Embed third-party assembly as a resource
// 1. Set build action 'Embedded Resourse'.
// 2. Run this handler as early as possible:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string resourceName = "Your.Assembly.Name.Here." + new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream == null)
{
return null;
}
var assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment