Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Once you've embedded the third-party assembly as a resource, add code to subscribe to the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx" rel="nofollow noreferrer"><code>AppDomain.AssemblyResolve</code></a> event of the current domain during application start-up. This event fires whenever the Fusion sub-system of the CLR fails to locate an assembly according to the probing (policies) in effect. In the event handler for <code>AppDomain.AssemblyResolve</code>, load the resource using <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcestream.aspx" rel="nofollow noreferrer"><code>Assembly.GetManifestResourceStream</code></a> and feed its content as a byte array into the corresponding <a href="http://msdn.microsoft.com/en-us/library/h538bck7.aspx" rel="nofollow noreferrer"><code>Assembly.Load</code></a> overload. Below is how one such implementation could look like in C#:</p> <pre><code>AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =&gt; { var resName = args.Name + ".dll"; var thisAssembly = Assembly.GetExecutingAssembly(); using (var input = thisAssembly.GetManifestResourceStream(resName)) { return input != null ? Assembly.Load(StreamToBytes(input)) : null; } }; </code></pre> <p>where <code>StreamToBytes</code> could be defined as:</p> <pre><code>static byte[] StreamToBytes(Stream input) { var capacity = input.CanSeek ? (int) input.Length : 0; using (var output = new MemoryStream(capacity)) { int readLength; var buffer = new byte[4096]; do { readLength = input.Read(buffer, 0, buffer.Length); output.Write(buffer, 0, readLength); } while (readLength != 0); return output.ToArray(); } } </code></pre> <p>Finally, as a few have already mentioned, <a href="http://research.microsoft.com/~mbarnett/ILMerge.aspx" rel="nofollow noreferrer">ILMerge</a> may be another option to consider, albeit somewhat more involved. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload