C# 使用DeploymentItem属性使用AutoMapper进行单元测试不起作用-PlatformNotSupportedException
我正试图在使用DeploymentItem属性的单元测试中使用AutoMapper,以便在运行时读取文件 这是我的密码:C# 使用DeploymentItem属性使用AutoMapper进行单元测试不起作用-PlatformNotSupportedException,c#,unit-testing,automapper-3,C#,Unit Testing,Automapper 3,我正试图在使用DeploymentItem属性的单元测试中使用AutoMapper,以便在运行时读取文件 这是我的密码: [TestClass] public class UnitTest1 { [TestMethod] [DeploymentItem("Samples/demo.csv")] public void TestMethod1() { Mapper.CreateMap&l
[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; }
}
[TestClass]
公共类UnitTest1
{
[测试方法]
[DeploymentItem(“Samples/demo.csv”)]
公共void TestMethod1()
{
来自AutoMapper的创建者的Mapper.CreateMap,但似乎没有解决该问题
例外情况详情如下:
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:
用户代码未处理System.TypeInitializationException异常
HResult=-21462036
Message=AutoMapper.TypeMapFactory的类型初始值设定项引发异常。
源=自动映射器
TypeName=AutoMapper.TypeMapFactory
堆栈跟踪:
在AutoMapper.TypeMapFactory..ctor()中
在AutoMapper.Mapper.b_uu0()上
在AutoMapper.Internal.LazyFactory.LazyImpl`1.get_Value()中
在AutoMapper.Mapper.get_ConfigurationProvider()上
在AutoMapper.Mapper.get_配置()中
在AutoMapper.Mapper.CreateMap[TSource,TDestination]()
在c:\TNS.visualstudio.com\Research Platform\Development\T4\TNS.T4.MVC.Tests\Mocks\UnitTest1.TestMethod1()中的TNS.T4.MVC.Tests\Mocks\UnitTest1.cs:第13行
InnerException:System.PlatformNotSupportedException
HResult=-21462031
Message=此平台IDictionaryFactory不支持此类型
源=自动映射器
堆栈跟踪:
在AutoMapper.Internal.PlatformAdapter.Resolve[T](布尔throwIfNotFound)
在AutoMapper.TypeMapFactory..cctor()中
内部异常:
谢谢!我认为这与部署项无关。我复制了该问题,但在安装安装包AutoMapper.NET35之后就消失了。欢迎使用,Javier.Reg:-“但是当我删除DeploymentItem属性时,测试就可以正常工作了。”你确定这一点吗?即使没有DeploymentItem attributeRaj,我也会遇到同样的错误,谢谢你的回答。只是在一个新项目上再次复制了错误,但仍然得到同样的错误。有趣的是,我使用VS 2012 11.0.60315.01 Update 2,其中包含.Net 4.5和resharper 7.1.3完整版,并且仍然得到与上面相同的情况已经安装了AutoMapper软件包,刚刚安装了您提到的软件包并完成了操作。谢谢!
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: