Unit testing with AutoMapper using DeploymentItem attribute not working – PlatformNotSupportedException

I’m trying to use AutoMapper with my unit tests that use DeploymentItem attributes in order to read files at runtime.

Here is my code:

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

I’m getting an error at this line:

Mapper.CreateMap<A, B>();

but when I remove the DeploymentItem attribute the test just works fine.

I have read this article from the creator of AutoMapper but doesn’t seem to addressing the problem.

Exception details below:

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: 

Thanks!

One answer on “Unit testing with AutoMapper using DeploymentItem attribute not working – PlatformNotSupportedException

  1. I don’t think this is Deployment Item related. I replicated the issue, but went away after installing install-package AutoMapper.NET35

Comments are closed.