早期版本的Autofac工作,但由于他们切换到使其成为可移植类库,它将无法加载.
我尝试应用此处列出的修复程序(KB2468871),但它告诉我它不需要.
当我将Autofac.dll文件移动到与可执行文件相同的位置时,错误消失了.当它从外部DLL加载它时,它加载正常.
为什么它不能作为嵌入式DLL工作?
这是一个例外:
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
Run Code Online (Sandbox Code Playgroud)
如果有帮助,这里是.csproj文件的一部分,它将DLL嵌入到可执行文件中:
<Target Name="AfterResolveReferences">
<ItemGroup>
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
...这里是EntryPoint类:
internal static …Run Code Online (Sandbox Code Playgroud)