Created
March 20, 2015 16:53
-
-
Save gowon/3758b0f19d21ec012089 to your computer and use it in GitHub Desktop.
Loading a library from internal resources instead of external references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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