Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If it is still the case that you <em>must</em> do this, then use this OnResolveAssembly method. There is no need to preload them into an array if you don't want to. This will load them the first time they are actually needed.</p> <p>Then just:</p> <ul> <li>add the <strong>some.assembly.dll</strong> file to the project.</li> <li><ul> <li>probably not a reference to the project's output</li> </ul></li> <li><ul> <li>but the file that is the result of the DLL project.</li> </ul></li> <li><p>mark it as a <strong>Resource</strong> in the file properties.</p> <pre><code>// This function is not called if the Assembly is already previously loaded into memory. // This function is not called if the Assembly is already in the same folder as the app. // private static Assembly OnResolveAssembly(object sender, ResolveEventArgs e) { var thisAssembly = Assembly.GetExecutingAssembly(); // Get the Name of the AssemblyFile var assemblyName = new AssemblyName(e.Name); var dllName = assemblyName.Name + ".dll"; // Load from Embedded Resources var resources = thisAssembly.GetManifestResourceNames().Where(s =&gt; s.EndsWith(dllName)); if (resources.Any()) { // 99% of cases will only have one matching item, but if you don't, // you will have to change the logic to handle those cases. var resourceName = resources.First(); using (var stream = thisAssembly.GetManifestResourceStream(resourceName)) { if (stream == null) return null; var block = new byte[stream.Length]; // Safely try to load the assembly. try { stream.Read(block, 0, block.Length); return Assembly.Load(block); } catch (IOException) { return null; } catch (BadImageFormatException) { return null; } } } // in the case the resource doesn't exist, return null. return null; } </code></pre></li> </ul> <p>-Jesse</p> <p>PS: This comes from <a href="http://www.paulrohde.com/merging-a-wpf-application-into-a-single-exe/" rel="nofollow">http://www.paulrohde.com/merging-a-wpf-application-into-a-single-exe/</a></p>
 

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