【发布时间】:2013-12-13 15:53:57
【问题描述】:
我很难说服 FxCop 10.0 分析引用 AutoMapper 的程序集。
我创建了一个简单的类库,通过 NuGet 引用了 AutoMapper,并添加了如下代码:
using System;
namespace ClassLibrary4
{
public class Class1
{
public void Foo()
{
AutoMapper.Mapper.CreateMap<Obj1, Obj2>()
.ForMember(x => x.Name, opt => opt.Ignore());
}
}
public class Obj1
{
public string Name { get; set; }
}
public class Obj2
{
public string Name { get; set; }
}
}
然后我尝试使用 FxCop 10.0 通过命令行分析程序集,并收到消息:
无法加载 C:\Users\inelson\Documents\Visual Studio 2013\Projects\ClassLibrary4\ClassLibrary4\bin\Debug\ClassLibrary4.dll。
注意:找不到一个或多个引用的程序集。使用“/directory”或“/reference”开关指定其他程序集引用搜索路径。
未解决的参考是 System.Core 版本 2.0.5.0。
为了隔离问题,我删除了 .ForMember 方法调用,只保留了 Foo():
public void Foo()
{
AutoMapper.Mapper.CreateMap<Obj1, Obj2>();
}
FxCop 10.0 现在可以愉快地分析程序集了!
.ForMember 方法导致 FxCop 分析失败的原因是什么?
请注意,我在使用 .NET Framework 4.0、4.5 或 4.5.1 以及 AutoMapper 3.0.0 和 3.1.0 时遇到了相同的行为。
【问题讨论】:
-
长镜头.. 但是您是否尝试过为 AutoMapper 扩展命名空间添加 using 语句?
-
使用 Fuslogvw.exe 解决程序集解析问题。
-
@HansPassant 我试过了,没有显示失败的绑定。
-
不确定你指的是哪个命名空间安迪 - 据我所知,没有 AutoMapper.Extensions 命名空间。 ForMember 不是扩展方法,它位于根 AutoMapper 命名空间中。
-
请提供命令 FxComCmd.exe /file:ClassLibrary4.dll /console /v 的输出。从您的问题来看,无法找到确切的程序集并不明显。通常,此错误如下所示:无法加载“Library.dll”。读取模块“库”时遇到以下错误:无法解析程序集引用:“dependencyStrongName”。
标签: .net automapper fxcop portable-class-library