We recently switched our automated unit tests from MSTest to VStest. After the switch several of the unit tests started failing giving the following error message,
Test method Domain.Model.IntegrationTests.Documents.DocumentFilesRepositoryTest.Delete_file_Page_not_shared_can_delete threw exception:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Runtime.Hosting.IClrStrongName'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9FD93CCF-3280-4391-B3A9-96E1CDE77C8D}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
Result 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) at System.Reflection.StrongNameKeyPair.ComputePublicKey() at System.Reflection.StrongNameKeyPair.get_PublicKey() at System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, 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 refusedPermissions, StackCrawlMark& stackMark, IEnumerable'1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, >AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet >requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, >StackCrawlMark& stackMark, IEnumerable`1 assemblyAttributes, SecurityContextSource >securityContextSource) at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess >access) at Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName) at Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName() at Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean isStrongNamed) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, >String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, >String name, Type baseType, Type[] interfaces, TypeAttributes flags) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, >String name, Type baseType, Type[] interfaces) at Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, >Type parentType, Type[] interfaces) at Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, >Type parentType, IList interfaceList) at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options) at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) at Rhino.Mocks.MockRepository.MockClass(CreateMockState mockStateFactory, Type type, Type[] extras, Object[] argumentsForConstructor) at Rhino.Mocks.MockRepository.CreateMockObject(Type type, CreateMockState factory, Type[] extras, Object[] argumentsForConstructor) at Rhino.Mocks.MockRepository.PartialMultiMock(Type type, Type[] extraTypes, Object[] argumentsForConstructor) at Rhino.Mocks.MockRepository.PartialMock(Type type, Object[] argumentsForConstructor) at Rhino.Mocks.MockRepository.PartialMock[T](Object[] argumentsForConstructor) at Model.IntegrationTests.Documents.DocumentFilesRepositoryTest.Delete_file_Page_not_shared_can_delete() in c:\TFS_DATA\Dev\BUILDCI\Common8\Tests\Integration\Domain.IntegrationTests\Documents\DocumentFilesRepositoryTest.cs:line 293
Our unit tests utilize RhinoMocks for mocking. Initially we suspected that it could be an issue with RhinoMocks because the target framework for the RhinoMocks assemblies is .NET 2.0 and we were using .NET 4.5. Therefore we rewrote the failing tests using Moq for mocking because Moq assemblies were available for the target framework 4.0. But we are still getting the same issue. Any suggestions what the root cause of the error might be?
User contributions licensed under CC BY-SA 3.0