在切换到VSTest后,无法将“System .__ ComObject”类型的COM对象转换为接口类型“Microsoft.Runtime.Hosting.IClrStrongName”

时间:2014-07-16 01:44:23

标签: .net unit-testing com strongname vstest

我们最近将自动化单元测试从MSTest切换到VStest。在切换之后,几个单元测试开始失败,并给出以下错误消息,

  

测试方法Domain.Model.IntegrationTests.Documents.DocumentFilesRepositoryTest.Delete_file_Page_not_shared_can_delete抛出异常:

     

System.InvalidCastException:无法转换类型为' System .__ ComObject'的COM对象。到界面类型' Microsoft.Runtime.Hosting.IClrStrongName'。此操作失败,因为QueryInterface调用COM组件上的接口与IID' {9FD93CCF-3280-4391-B3A9-96E1CDE77C8D}'由于以下错误而失败:接口未注册(HRESULT异常:0x80040155)。

     

结果StackTrace:

     

at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc,IntPtr pCPCMD,IntPtr& ppTarget,Boolean& pfNeedsRelease)     at Microsoft.Runtime.Hosting.IClrStrongName.StrongNameGetPublicKey(String pwzKeyContainer,Byte [] pbKeyBlob,Int32 cbKeyBlob,IntPtr& ppbPublicKeyBlob,Int32& pcbPublicKeyBlob)     at Microsoft.Runtime.Hosting.StrongNameHelpers.StrongNameGetPublicKey(String pwzKeyContainer,Byte [] bKeyBlob,Int32 cbKeyBlob,IntPtr& ppbPublicKeyBlob,Int32& pcbPublicKeyBlob)     在System.Reflection.StrongNameKeyPair.ComputePublicKey()     在System.Reflection.StrongNameKeyPair.get_PublicKey()     在System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain域,AssemblyName名称,AssemblyBuilderAccess访问,String目录,证据证据,PermissionSet requiredPermissions,PermissionSet optionalPermissions,PermissionSet rejectedPermissions,StackCrawlMark& stackMark,IEnumerable' 1 unsafeAssemblyAttributes,SecurityContextSource securityContextSource)     at System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(AssemblyName name,AssemblyBuilderAccess access,String dir,Evidence evidence,PermissionSet requiredPermissions,PermissionSet optionalPermissions,PermissionSet rejectedPermissions,StackCrawlMark& stackMark,IEnumerable' 1 unsafeAssemblyAttributes,SecurityContextSource securityContextSource)     在System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name,> AssemblyBuilderAccess访问,String dir,证据证据,PermissionSet> requiredPermissions,PermissionSet optionalPermissions,PermissionSet rejectedPermissions,> StackCrawlMark& stackMark,IEnumerable`1 assemblyAttributes,SecurityContextSource> securityContextSource)     在System.AppDomain.DefineDynamicAssembly(AssemblyName名称,AssemblyBuilderAccess>访问)     在Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName)     在Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName()     在Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean isStrongNamed)     在Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(ModuleScope modulescope,String name,Type baseType,Type [] interfaces,TypeAttributes flags,Boolean forceUnsigned)     在Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope,> String name,Type baseType,Type [] interfaces,TypeAttributes flags,Boolean forceUnsigned)     在Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope,> String name,Type baseType,Type [] interfaces,TypeAttributes flags)     在Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope,> String name,Type baseType,Type [] interfaces)     在Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName,> Type parentType,Type [] interfaces)     在Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName,> Type parentType,IList interfaceList)     在Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type []接口,ProxyGenerationOptions选项)     在Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(类型classToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项)      在Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(类型classToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项)      在Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(类型classToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项,Object [] constructorArguments,IInterceptor []拦截器)      在Rhino.Mocks.MockRepository.MockClass(CreateMockState mockStateFactory,Type type,Type [] extras,Object [] argumentsForConstructor)      在Rhino.Mocks.MockRepository.CreateMockObject(Type type,CreateMockState factory,Type [] extras,Object [] argumentsForConstructor)      在Rhino.Mocks.MockRepository.PartialMultiMock(Type type,Type [] extraTypes,Object [] argumentsForConstructor)      在Rhino.Mocks.MockRepository.PartialMock(Type type,Object [] argumentsForConstructor)      在Rhino.Mocks.MockRepository.PartialMock [T](Object [] argumentsForConstructor)      在C:\ TFS_DATA \ Dev \ BUILDCI \ Common8 \ Tests \ Integration \ Domain.IntegrationTests \ Documents \ DocumentFilesRepositoryTest.cs中的Model.IntegrationTests.Documents.DocumentFilesRepositoryTest.Delete_file_Page_not_shared_can_delete():第293行

我们的单元测试使用RhinoMocks进行模拟。最初我们怀疑它可能是RhinoMocks的一个问题,因为RhinoMocks程序集的目标框架是.NET 2.0,我们使用的是.NET 4.5。因此,我们使用Moq重写了用于模拟的失败测试,​​因为Moq程序集可用于目标框架4.0。但我们仍然遇到同样的问题。有什么建议可能是错误的根本原因吗?

0 个答案:

没有答案