Note that there are some explanatory texts on larger screens.

plurals
  1. POFileNotFoundException when trying to load Autofac as an embedded assembly
    primarykey
    data
    text
    <p>Previous versions of Autofac worked, but since they switched to making it a Portable Class Library it won't load.</p> <p>I tried applying the fix listed <a href="https://code.google.com/p/autofac/wiki/FrequentlyAskedQuestions">here</a> (KB2468871) but it told me that it was not needed.</p> <p>The error goes away when I move the Autofac.dll file into the same location as the executable. When it loads it from the external DLL it loads fine.</p> <p>Why won't it work as an embedded DLL?</p> <p>Here is the exception:</p> <pre><code> System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified. Stack trace: at Autofac.Core.Registration.ComponentRegistration..ctor(Guid id, IInstanceActivator activator, IComponentLifetime lifetime, InstanceSharing sharing, InstanceOwnership ownership, IEnumerable`1 services, IDictionary`2 metadata) at Autofac.Core.Container..ctor() at Autofac.ContainerBuilder.Build(ContainerBuildOptions options) at MyApp.Configuration.Bootstrapper.Run(String[] args) in c:\Dev\MyApp\App\Configuration\Bootstrapper.cs:line 25 at MyApp.Configuration.EntryPoint.Main(String[] args) in c:\Dev\MyApp\App\Configuration\EntryPoint.cs:line 22 </code></pre> <p>If it helps, here is the part of the .csproj file that embeds the DLLs into the executable:</p> <pre><code> &lt;Target Name="AfterResolveReferences"&gt; &lt;ItemGroup&gt; &lt;EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'"&gt; &lt;LogicalName&gt;%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)&lt;/LogicalName&gt; &lt;/EmbeddedResource&gt; &lt;/ItemGroup&gt; </code></pre> <p></p> <p>... and here is the EntryPoint class:</p> <pre><code>internal static class EntryPoint { [STAThread] private static void Main(params string[] args) { AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =&gt; loadEmbeddedAssembly(e.Name); Bootstrapper.Run(args); // must call separate class when using embedded assemblies } private static Assembly loadEmbeddedAssembly(string name) { var container = Assembly.GetExecutingAssembly(); var path = new AssemblyName(name).Name + ".dll"; using (var stream = container.GetManifestResourceStream(path)) { if (stream == null) { return null; } var bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); return Assembly.Load(bytes); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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