Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeLoad Exception #241

Closed
ShaneCarr opened this issue Jan 15, 2016 · 3 comments
Closed

TypeLoad Exception #241

ShaneCarr opened this issue Jan 15, 2016 · 3 comments

Comments

@ShaneCarr
Copy link

The scenario: We are having a problem mocking an interface which is public. It is in a signed assembly which is a dependency of our dev code (we don't directly own the assembly).

The interface has a number return values which are concrete types (on methods i am not directly using our testing) and they are public. If i remove personal the problem just moves down to the next class.

For example these methods
ICollection DirectorySearch(ViewBase view, string queryString);
and
FindPeopleResults FindPeople(WellKnownFolderName wellKnownFolderName, SearchFilter filter, ItemView view);

Everything is public (no internal visible to i believe should be required). I don't see any reason these shoudl be casuing this type of issue, i am not actually mocking these or using these properties in my code the exception happens on the ".object" to generate the mock.

GetConversationScreenResponse getConversationScreenResponse = this.NewGetConversationScreenCommand(serviceMock.Object, flowFolderMock.Object).Execute(flowConversationId);

We also aren't mocking any of these methods that are causing the problem. it seems to be triggered by reflection in moq scanning the object and throwing an exception. I included the call stack below and the call stack from the test case. I spent a while on this any suggestions would be greatly appreciated!
Test Name: SingleFlowOriginatedOneOnOneMessageInConversation
Test FullName: Microsoft.OutlookApps.Flow.Api.Tests.GetConversationScreenCommandTests.SingleFlowOriginatedOneOnOneMessageInConversation
Test Source: C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApi.Tests\GetConversationScreenCommandTests.cs : line 59
Test Outcome: Failed
Test Duration: 0:00:00.0089433

Result StackTrace:
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at Castle.DynamicProxy.Generators.MethodSignatureComparer.GetHashCode(MethodInfo obj)
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at Castle.DynamicProxy.Generators.MethodFinder.RemoveDuplicates(MethodInfo[] infos) at Castle.DynamicProxy.Generators.MethodFinder.GetAllInstanceMethods(Type type, BindingFlags flags) at Castle.DynamicProxy.Contributors.MembersCollector.CollectMethods(IProxyGenerationHook hook) at Castle.DynamicProxy.Contributors.MembersCollector.CollectMembersToProxy(IProxyGenerationHook hook) at Castle.DynamicProxy.Contributors.InterfaceProxyWithoutTargetContributor.<CollectElementsToProxyInternal>d__0.MoveNext() at Castle.DynamicProxy.Contributors.CompositeTypeContributor.CollectElementsToProxy(IProxyGenerationHook hook, MetaType model) at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope) at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass1.<GenerateCode>b__0(String n, INamingScope s) at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func3 factory)
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
at Moq.Mock1.<InitializeInstance>b__2() at Moq.PexProtector.Invoke(Action action) at Moq.Mock1.InitializeInstance()
at Moq.Mock1.OnGetObject() at Moq.Mock1.get_Object()
at Microsoft.OutlookApps.Flow.Api.Tests.GetConversationScreenCommandTests.SingleFlowOriginatedOneOnOneMessageInConversation() in C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApi.Tests\GetConversationScreenCommandTests.cs:line 67
Result Message:
Test method Microsoft.OutlookApps.Flow.Api.Tests.GetConversationScreenCommandTests.SingleFlowOriginatedOneOnOneMessageInConversation threw exception:
System.TypeLoadException: Could not load type 'Microsoft.Exchange.WebServices.Data.Persona' from assembly 'Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Here is some sample code that seems to be causing the problem.

namespace Microsoft.Exchange.WebServices.Data
{
[Attachable, ServiceObjectDefinition("Persona")]
public class Persona : Item

...

[Attachable, ServiceObjectDefinition("Item")]
public class Item : ServiceObject
@kzu
Copy link
Member

kzu commented Jan 15, 2016

Plz try to repro with plain DynamicProxy or NSubstitute / FakeItEasy. If it
reproes (In almost sure if will), it's a Castle issue, not a Moq issue, I'm
afraid

On Fri, Jan 15, 2016, 12:47 AM shanepcarr notifications@github.com wrote:

The scenario: We are having a problem mocking an interface which is public
It is in a signed assembly which is a dependency of our dev code (we don't
directly own the assembly)

The interface has a number return values which are concrete types (on
methods i am not directly using our testing) and they are public If i
remove personal the problem just moves down to the next class

For example these methods
ICollection DirectorySearch(ViewBase view, string queryString);
and
FindPeopleResults FindPeople(WellKnownFolderName wellKnownFolderName,
SearchFilter filter, ItemView view);

Everything is public (no internal visible to i believe should be required)
I don't see any reason these shoudl be casuing this type of issue, i am not
actually mocking these or using these properties in my code the exception
happens on the "object" to generate the mock

GetConversationScreenResponse getConversationScreenResponse =
thisNewGetConversationScreenCommand(serviceMockObject,
flowFolderMockObject)Execute(flowConversationId);

We also aren't mocking any of these methods that are causing the problem
it seems to be triggered by reflection in moq scanning the object and
throwing an exception I included the call stack below and the call stack
from the test case I spent a while on this any suggestions would be greatly
appreciated!
Test Name: SingleFlowOriginatedOneOnOneMessageInConversation
Test FullName:
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation
Test Source:
C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApiTests\GetConversationScreenCommandTestscs
: line 59
Test Outcome: Failed
Test Duration: 0:00:000089433

Result StackTrace:

at SystemSignatureGetSignature(Void* pCorSig, Int32 cCorSig,
RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle,
RuntimeType declaringType)
at SystemReflectionRuntimeMethodInfoFetchNonReturnParameters()
at SystemReflectionRuntimeMethodInfoGetParameters()
at
CastleDynamicProxyGeneratorsMethodSignatureComparerGetHashCode(MethodInfo
obj)
at SystemCollectionsGenericDictionary2FindEntry(TKey key)
at CastleDynamicProxyGeneratorsMethodFinderRemoveDuplicates(MethodInfo[]
infos)
at CastleDynamicProxyGeneratorsMethodFinderGetAllInstanceMethods(Type
type, BindingFlags flags)
at
CastleDynamicProxyContributorsMembersCollectorCollectMethods(IProxyGenerationHook
hook)
at
CastleDynamicProxyContributorsMembersCollectorCollectMembersToProxy(IProxyGenerationHook
hook)
at
CastleDynamicProxyContributorsInterfaceProxyWithoutTargetContributord__0MoveNext()
at
CastleDynamicProxyContributorsCompositeTypeContributorCollectElementsToProxy(IProxyGenerationHook
hook, MetaType model)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithoutTargetGeneratorGenerateType(String
typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithTargetGenerator<>c__DisplayClass1b__0(String
n, INamingScope s)
at CastleDynamicProxyGeneratorsBaseProxyGeneratorObtainProxyType(CacheKey
cacheKey, Func3 factory)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithTargetGeneratorGenerateCode(Type
proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at
CastleDynamicProxyDefaultProxyBuilderCreateInterfaceProxyTypeWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options)
at CastleDynamicProxyProxyGeneratorCreateInterfaceProxyWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options, IInterceptor[] interceptors)
at MoqProxyCastleProxyFactoryCreateProxy(Type mockType, ICallInterceptor
interceptor, Type[] interfaces, Object[] arguments)
at MoqMock1b__2()
at MoqPexProtectorInvoke(Action action)
at MoqMock1InitializeInstance()
at MoqMock1OnGetObject()
at MoqMock1get_Object()
at
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation()
in
C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApiTests\GetConversationScreenCommandTestscs:line
67
Result Message:
Test method
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation
threw exception:
SystemTypeLoadException: Could not load type
'MicrosoftExchangeWebServicesDataPersona' from assembly
'MicrosoftExchangeWebServices, Version=15000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'

Here is some sample code that seems to be causing the problem

namespace MicrosoftExchangeWebServicesData
{
[Attachable, ServiceObjectDefinition("Persona")]
public class Persona : Item

[Attachable, ServiceObjectDefinition("Item")]
public class Item : ServiceObject


Reply to this email directly or view it on GitHub
#241.

@ShaneCarr
Copy link
Author

OK I will give that a shot and let you know

Sent from Outlook Mobile

On Thu, Jan 14, 2016 at 8:06 PM -0800, "Daniel Cazzulino" notifications@github.com wrote:

Plz try to repro with plain DynamicProxy or NSubstitute / FakeItEasy. If it
reproes (In almost sure if will), it's a Castle issue, not a Moq issue, I'm
afraid

On Fri, Jan 15, 2016, 12:47 AM shanepcarr notifications@github.com wrote:

The scenario: We are having a problem mocking an interface which is public
It is in a signed assembly which is a dependency of our dev code (we don't
directly own the assembly)

The interface has a number return values which are concrete types (on
methods i am not directly using our testing) and they are public If i
remove personal the problem just moves down to the next class

For example these methods
ICollection DirectorySearch(ViewBase view, string queryString);
and
FindPeopleResults FindPeople(WellKnownFolderName wellKnownFolderName,
SearchFilter filter, ItemView view);

Everything is public (no internal visible to i believe should be required)
I don't see any reason these shoudl be casuing this type of issue, i am not
actually mocking these or using these properties in my code the exception
happens on the "object" to generate the mock

GetConversationScreenResponse getConversationScreenResponse =
thisNewGetConversationScreenCommand(serviceMockObject,
flowFolderMockObject)Execute(flowConversationId);

We also aren't mocking any of these methods that are causing the problem
it seems to be triggered by reflection in moq scanning the object and
throwing an exception I included the call stack below and the call stack
from the test case I spent a while on this any suggestions would be greatly
appreciated!
Test Name: SingleFlowOriginatedOneOnOneMessageInConversation
Test FullName:
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation
Test Source:
C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApiTests\GetConversationScreenCommandTestscs
: line 59
Test Outcome: Failed
Test Duration: 0:00:000089433

Result StackTrace:

at SystemSignatureGetSignature(Void* pCorSig, Int32 cCorSig,
RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle,
RuntimeType declaringType)
at SystemReflectionRuntimeMethodInfoFetchNonReturnParameters()
at SystemReflectionRuntimeMethodInfoGetParameters()
at
CastleDynamicProxyGeneratorsMethodSignatureComparerGetHashCode(MethodInfo
obj)
at SystemCollectionsGenericDictionary2FindEntry(TKey key)
at CastleDynamicProxyGeneratorsMethodFinderRemoveDuplicates(MethodInfo[]
infos)
at CastleDynamicProxyGeneratorsMethodFinderGetAllInstanceMethods(Type
type, BindingFlags flags)
at
CastleDynamicProxyContributorsMembersCollectorCollectMethods(IProxyGenerationHook
hook)
at
CastleDynamicProxyContributorsMembersCollectorCollectMembersToProxy(IProxyGenerationHook
hook)
at
CastleDynamicProxyContributorsInterfaceProxyWithoutTargetContributord__0MoveNext()
at
CastleDynamicProxyContributorsCompositeTypeContributorCollectElementsToProxy(IProxyGenerationHook
hook, MetaType model)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithoutTargetGeneratorGenerateType(String
typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithTargetGenerator<>c__DisplayClass1b__0(String
n, INamingScope s)
at CastleDynamicProxyGeneratorsBaseProxyGeneratorObtainProxyType(CacheKey
cacheKey, Func3 factory)
at
CastleDynamicProxyGeneratorsInterfaceProxyWithTargetGeneratorGenerateCode(Type
proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at
CastleDynamicProxyDefaultProxyBuilderCreateInterfaceProxyTypeWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options)
at CastleDynamicProxyProxyGeneratorCreateInterfaceProxyWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options, IInterceptor[] interceptors)
at MoqProxyCastleProxyFactoryCreateProxy(Type mockType, ICallInterceptor
interceptor, Type[] interfaces, Object[] arguments)
at MoqMock1b__2()
at MoqPexProtectorInvoke(Action action)
at MoqMock1InitializeInstance()
at MoqMock1OnGetObject()
at MoqMock1get_Object()
at
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation()
in
C:\Users\shcarr\wp\gservice\GroupiesCloudService\DirectMessagingApiTests\GetConversationScreenCommandTestscs:line
67
Result Message:
Test method
MicrosoftOutlookAppsFlowApiTestsGetConversationScreenCommandTestsSingleFlowOriginatedOneOnOneMessageInConversation
threw exception:
SystemTypeLoadException: Could not load type
'MicrosoftExchangeWebServicesDataPersona' from assembly
'MicrosoftExchangeWebServices, Version=15000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'

Here is some sample code that seems to be causing the problem

namespace MicrosoftExchangeWebServicesData
{
[Attachable, ServiceObjectDefinition("Persona")]
public class Persona : Item

[Attachable, ServiceObjectDefinition("Item")]
public class Item : ServiceObject


Reply to this email directly or view it on GitHub
#241.


Reply to this email directly or view it on GitHub:
#241 (comment)

@ShaneCarr
Copy link
Author

Thanks again for the response. I figured out this problem, it had nothing to do with castle or MOQ. Posting the resolution as other people will likely face similar issue and this investigation may help.

The problem was we had a custom build assembly that didn't match assembly which was getting loaded from the gac before my suite ever ran, but we had built against the custom built assembly. The lesson is to break on exceptions and look at the loaded modules to double check that you have the right assemblies loaded then look at the il. This was tricky because this assembly was being loaded by vs and we have a custom built version improperly versioned which I didn't know about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants