Domanda

I am having difficulty persuading FxCop 10.0 to analyse assemblies that reference AutoMapper.

I have created a simple class library, referenced AutoMapper via NuGet, and added the following code:

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; }
    }
}

I then tried to use FxCop 10.0 to analyse the assembly via the command line, and receive the message:

Could not load C:\Users\inelson\Documents\Visual Studio 2013\Projects\ClassLibrary4\ClassLibrary4\bin\Debug\ClassLibrary4.dll.

NOTE: One or more referenced assemblies could not be found. Use the '/directory' or '/reference' switch to specify additional assembly reference search paths.

Unresolved reference is to System.Core Version 2.0.5.0.

In an effort to isolate the issue, I removed the .ForMember method call, leaving Foo() as simply:

public void Foo() 
{
    AutoMapper.Mapper.CreateMap<Obj1, Obj2>(); 
}

and FxCop 10.0 now happily analyses the assembly!

What is it with the .ForMember method that is causing the FxCop analysis to fail?

Note that I am experiencing the same behaviour with .NET Framework versions 4.0, 4.5 or 4.5.1, and AutoMapper 3.0.0 and 3.1.0.

È stato utile?

Soluzione

Make sure that AutoMapper.dll exists in output directory (in your case it is C:\Users\inelson\Documents\Visual Studio 2013\Projects\ClassLibrary4\ClassLibrary4\bin\Debug)

UPDATE: It is a well known problem with Portable Libraries and FxCop. Please, see answers:

This problem also discussed in AutoMapper bugtracker.

UPDATE 2: And I'm pretty sure that problem appears because FxCop standalone version doesn't support .NET 4.5 and Portable Class Libraries. You can vote for appropriate suggestion on Visual Studio User Voice.

Did you try to run code analysis via Visual Studio?

UPDATE 3: I try to run 11.0.50727.1 version of FxCopCmd.exe which installed with Visual Studio 2012 (I found it at C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop) and it seems to work.

Also, I try to run Code Analysis in Visual Studio 2012 and it also works.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top