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

Sporatic TypeLoadException or MissingMethodException during unit test execution #246

Closed
Schaeri opened this issue Feb 10, 2016 · 1 comment

Comments

@Schaeri
Copy link

Schaeri commented Feb 10, 2016

We have a very strange problem in our project when running unit tests. In very rare cases some tests fail with TypeLoadException or MissingMethodException when calling mocked methods. The tests which are failing are never the same. It is absolutely random which test will fail. We have approximately 25000 Tests. Every 20 build fails with such an error on a single unit test.
We run our tests with xunit 2.1 in parallel, all in the same app domain. Our moq version is 4.2.1510.2205.

We try to reproduce the error by accessing moq and castle in parallel from several threads but were never able to reproduce the issue on a simple example. We also tried to create simple unit test example projects without any luck.

Any idea what can cause our problem? Thanks for the help.

Sample Type Load Exception:
Erowa.EMC.Machines.FileIO.JobProgramsProcessorTest.ProcessPrograms_MustReturnProcessedPartProgram [FAIL]
System.TypeLoadException : Could not load type 'Castle.Proxies.Invocations.IMocked_get_Mock' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=a621a9e7e5c32e69'.
Stack Trace:
at Castle.Proxies.IEmcFileProxy.get_Mock()
at Moq.Proxy.InterfaceProxy.ToString()
at Moq.ExpressionStringBuilder.ToStringConstant(ConstantExpression c)
at Moq.ExpressionStringBuilder.ToString(Expression exp)
at Moq.ExpressionStringBuilder.AsCommaSeparatedValues[T](IEnumerable1 source, Action1 toStringAction)
at Moq.ExpressionStringBuilder.ToStringMethodCall(MethodCallExpression node)
at Moq.ExpressionStringBuilder.ToString(Expression exp)
at Moq.ExpressionStringBuilder.ToStringLambda(LambdaExpression lambda)
at Moq.ExpressionStringBuilder.ToString(Expression exp)
at Moq.ExpressionStringBuilder.ToString()
at Moq.ExpressionExtensions.ToStringFixed(Expression expression, Boolean useFullTypeName)
at Moq.Interceptor.AddCall(IProxyCall call, SetupKind kind)
at Moq.Mock.<>c__DisplayClass1c2.<Setup>b__1b() at Moq.PexProtector.Invoke[T](Func1 function)
at Moq.Mock.Setup[T,TResult](Mock1 mock, Expression1 expression, Condition condition)
Machines\FileIO\JobProgramsProcessorTest.cs(130,0): at Erowa.EMC.Machines.FileIO.JobProgramsProcessorTest.SetupProgramProcessor(IEmcFile inputProgram)
Machines\FileIO\JobProgramsProcessorTest.cs(91,0): at Erowa.EMC.Machines.FileIO.JobProgramsProcessorTest.ProcessPrograms_MustReturnProcessedPartProgram()

Sample Missing Method Exception:
[10:55:32][Step 1/1] xUnit.net Tests
[10:55:32][xUnit.net Tests] Erowa.EMC.Results.ResultBuilderTest.WithActionIf_MustConfigureIfBranch
[10:55:32][Erowa.EMC.Results.ResultBuilderTest.WithActionIf_MustConfigureIfBranch] System.MissingMethodException : Method not found: 'Void Castle.Proxies.Invocations.IResultBuilder_WithAction..ctor(Erowa.EMC.Results.IResultBuilder, System.Object, Castle.DynamicProxy.IInterceptor[], System.Reflection.MethodInfo, System.Object[])'.
[10:55:32]
[Erowa.EMC.Results.ResultBuilderTest.WithActionIf_MustConfigureIfBranch] at Castle.Proxies.IResultBuilderProxy.WithAction[TAction](Action1 executionAction) at Erowa.EMC.Results.ResultBuilder.<>c__DisplayClass15_01.b__0(IResultBuilder ifScope) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation\Results\ResultBuilder.cs:line 99
at Erowa.EMC.Results.ResultBuilderTest.<>c__DisplayClass16_0.<WithActionIf_MustConfigureIfBranch>b__1(Func1 condition, Action1 ifConfigure, Action1 elseConfigure) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation.Test\Results\ResultBuilderTest.cs:line 165 at Castle.Proxies.IResultBuilderProxy.WithAction[TAction](Action1 executionAction)
at Erowa.EMC.Results.ResultBuilder.<>c__DisplayClass15_01.<WithActionIf>b__0(IResultBuilder ifScope) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation\Results\ResultBuilder.cs:line 99 at Erowa.EMC.Results.ResultBuilderTest.<>c__DisplayClass16_0.<WithActionIf_MustConfigureIfBranch>b__1(Func1 condition, Action1 ifConfigure, Action1 elseConfigure) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation.Test\Results\ResultBuilderTest.cs:line 165 at Moq.Extensions.InvokePreserveStack(Delegate del, Object[] args)
at Moq.MethodCall.<>c__DisplayClass8.b__7(Object[] args)
at Moq.MethodCall.Execute(ICallContext call)
at Moq.MethodCallReturn2.Execute(ICallContext call) at Moq.ExecuteCall.HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx) at Moq.Interceptor.Intercept(ICallContext invocation) at Moq.Proxy.CastleProxyFactory.Interceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.IBranchingResultFactoryProxy.IfElse(Func1 condition, Action1 ifConfigure, Action1 elseConfigure)
at Erowa.EMC.Results.ResultBuilder.If(Func1 condition, Action1 ifConfigure) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation\Results\ResultBuilder.cs:line 77
at Erowa.EMC.Results.ResultBuilder.WithActionIf[TAction](Func1 condition, Action1 executionAction) in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation\Results\ResultBuilder.cs:line 99
at Erowa.EMC.Results.ResultBuilderTest.WithActionIf_MustConfigureIfBranch() in C:\BuildAgent\work\bf1bb0868d3bd9db\net\source\Erowa.EMC.Foundation.Test\Results\ResultBuilderTest.cs:line 16

@stakx
Copy link
Contributor

stakx commented Oct 20, 2017

@Schaeri, I hope you don't mind, but I'm closing this issue for now. We've been tracking this problem mostly over at the Castle Core issue tracker, and it's looking as if this might be a problem within the runtime / JIT. The way things are, I don't expect that there's anything we can do in Moq. If, however, we discover that the problem is indeed caused by Moq, I'll happily reopen this.

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

No branches or pull requests

2 participants