AutoMoq: DynamicProxy2 error for IList return values.


Executing this test:
public class Tests
    public interface IDataService
        IList<int> GetData ();

    public class TestedService
        private readonly IDataService dataService;

        public TestedService (IDataService dataService)
            this.dataService = dataService;

        public int DoSomething ()
            var data = this.dataService.GetData ();
            var result = 0;

            foreach (var x in data)
                result += x;

            return result;

    public void Test ()
        // arrange
        var fixture = new Fixture ();
        fixture.Customize (new AutoMoqCustomization ());

        // act
        var result = fixture.Create<TestedService> ().DoSomething ();

        // assert
        Assert.IsTrue (result > 0);
Gets me:
Test method Bug.Tests.Test threw exception: 
System.NotImplementedException: This is a DynamicProxy2 error: The interceptor attempted to 'Proceed' for method 'System.Collections.Generic.IEnumerator`1[System.Int32] GetEnumerator()' which has no target. When calling method without target there is no implementation to 'proceed' to and it is the responsibility of the interceptor to mimic the implementation (set return value, out arguments etc)
    at Castle.DynamicProxy.AbstractInvocation.ThrowOnNoTarget()
   at Castle.DynamicProxy.Internal.CompositionInvocation.EnsureValidTarget()
   at Castle.Proxies.Invocations.IEnumerable`1_GetEnumerator.InvokeMethodOnTarget()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Moq.Proxy.CastleProxyFactory.CallContext.InvokeBase()
   at Moq.InvokeBase.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.IList`1Proxy.GetEnumerator()
   at Bug.Tests.TestedService.DoSomething() in Tests.cs: line 34
   at Bug.Tests.Test() in Tests.cs: line 52
  • AutoFixture 3.19.2
  • AutoFixture.AutoMoq 3.19.2
  • Moq 4.2.1408.0717


ploeh wrote Aug 9, 2014 at 10:44 AM

Thank you for writing. Could you please repost the issue on GitHub?

AutoFixture migrated to GitHub more than two years ago.

While I could copy your issue to GitHub myself, if I do that, you wouldn't get any notifications about updates, answers, etc.

FuriCuri wrote Aug 18, 2014 at 7:06 AM

Sorry for delay.