Skip to content

Instantly share code, notes, and snippets.

@gowon
Created March 20, 2015 16:53
Show Gist options
  • Select an option

  • Save gowon/3758b0f19d21ec012089 to your computer and use it in GitHub Desktop.

Select an option

Save gowon/3758b0f19d21ec012089 to your computer and use it in GitHub Desktop.
Loading a library from internal resources instead of external references.
// Place this code in the initialization section of your code.
// http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = "AssemblyLoadingAndReflection." +
new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
Byte[] 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