Created
December 23, 2013 08:32
-
-
Save YBogomolov/8093485 to your computer and use it in GitHub Desktop.
Embed third-party assembly as a resource
This file contains 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
// 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