c# – 使用DeploymentItem属性无法使用AutoMapper进行单元测试 – PlatformNotSupportedException

我正在尝试将AutoMapper与使用DeploymentItem属性的单元测试一起使用,以便在运行时读取文件.

这是我的代码:

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        [DeploymentItem("Samples/demo.csv")]
        public void TestMethod1()
        {
            Mapper.CreateMap<A, B>();

            // test logic
        }
    }

    class A
    {
        public string PropA { get; set; }
        public bool PropB { get; set; }
    }

    class B
    {
        public string PropA { get; set; }
        public bool PropB { get; set; }
    }

我在这一行收到错误:

Mapper.CreateMap<A, B>();

但是当我删除DeploymentItem属性时,测试工作正常.

我从AutoMapper的创建者那里读过this article,但似乎没有解决这个问题.

以下例外情况:

System.TypeInitializationException was unhandled by user code
  HResult=-2146233036
  Message=The type initializer for 'AutoMapper.TypeMapFactory' threw an exception.
  Source=AutoMapper
  TypeName=AutoMapper.TypeMapFactory
  StackTrace:
       at AutoMapper.TypeMapFactory..ctor()
       at AutoMapper.Mapper.<.cctor>b__0()
       at AutoMapper.Internal.LazyFactory.LazyImpl`1.get_Value()
       at AutoMapper.Mapper.get_ConfigurationProvider()
       at AutoMapper.Mapper.get_Configuration()
       at AutoMapper.Mapper.CreateMap[TSource,TDestination]()
       at TNS.T4.MVC.Tests.Mocks.UnitTest1.TestMethod1() in c:\tns.visualstudio.com\Research Platform\Development\T4\TNS.T4.MVC.Tests\Mocks\UnitTest1.cs:line 13
  InnerException: System.PlatformNotSupportedException
       HResult=-2146233031
       Message=This type is not supported on this platform IDictionaryFactory
       Source=AutoMapper
       StackTrace:
            at AutoMapper.Internal.PlatformAdapter.Resolve[T](Boolean throwIfNotFound)
            at AutoMapper.TypeMapFactory..cctor()
       InnerException: 

谢谢!

最佳答案 我不认为这是部署项目相关.我复制了这个问题,但在安装install-package AutoMapper.NET35之后就消失了

点赞