相关疑难解决方法(0)

尝试将Autofac加载为嵌入式程序集时出现FileNotFoundException

早期版本的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)

c# dll embedded-resource

9
推荐指数
1
解决办法
3256
查看次数

错误 CS7069:对类型“x”的引用声称它在“y”中定义,但找不到;MSBuild 14

我在 Visual Studio 2017 中遇到了一个奇怪的问题。最近我们内部 nuget 包的变化将一个在扩展中使用的类移动到另一个项目/包,但命名空间没有改变。在另一个解决方案中更新新包后,扩展方法开始抛出编译错误。

“对类型 'x' 的引用声称它在 'y' 中定义,但找不到它”

我可以通过更改扩展方法以用作静态调用、使用 Visual Studio 2013 或让 resharper 构建使用 msbuild 12(14 和 15 抛出相同的错误)来获得要构建的解决方案。

我尝试过清除缓存、删除包和恢复、重新启动所有内容以及在单独的文件夹中重新结帐。还查看了其他有相同错误的问题,但他们提到的没有任何效果。

我确实计划让移动课程的团队修复命名空间以匹配项目,但需要几周时间才能完成。

前任:

//In project Company.Auto 
namespace Company.Auto.Extensions
{
   using System;

   public static class Cars
   {
       public static IDictionary<string, Car> DoStuff(this Car car)
       {
       }
   }
}

//Moved to project Company.Stuff.Something.Documents
namespace Company.Auto.Domain
{
   using System;

   public class Car
   {

   }
}
Run Code Online (Sandbox Code Playgroud)

c# visual-studio visual-studio-2017

6
推荐指数
1
解决办法
883
查看次数