This is a migrated thread and some comments may be shown as answers.

Dynamic nonPublic Wrap object getting error Array may not be empty. Parameter name: match

1 Answer 30 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Rafael asked on 20 Nov 2020, 12:50 AM


I have an interesting problem I am trying to solve unit testing Sitecore. I have wrapped myController to get to a dynamic accessor and I am getting an exception way down in the mscorplib System.DefaultBinder. Looking for leads on what I am missing on my setup?


System.ArgumentException: Array may not be empty.
Parameter name: match



    var controllerAccessor = Mock.NonPublic.Wrap(_myController);




Stack trace:

   at System.DefaultBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, Object& state)
   at Telerik.JustMock.Core.MockingUtil.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo culture, String[] names, Object& state)
   at Telerik.JustMock.PrivateAccessor.ResolveProperty(Type type, String name, Boolean ignoreCase, Object[] indexArgs, Boolean hasInstance, Object setterValue, Boolean getter)
   at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.DoBindGetMember(Type returnType, String memberName, Boolean ignoreCase)
   at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
   at System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)

at <my code line Mock.NonPublic.Arrange<IMyParameters>(controllerAccessor.GetRenderingParameters<IMyParameters>()).Returns(_myParameters)> 


System.DefaultBinder code snippet:

// Decompiled with JetBrains decompiler
// Type: System.DefaultBinder
// Assembly: mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: CACD6C6A-C61D-45CD-B58B-92E86EE53F52
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;

namespace System
  internal class DefaultBinder : Binder
    public override MethodBase BindToMethod(
      BindingFlags bindingAttr,
      MethodBase[] match,
      ref object[] args,
      ParameterModifier[] modifiers,
      CultureInfo cultureInfo,
      string[] names,
      out object state)
      MethodBase[] methodBaseArray = match != null && match.Length != 0 ? (MethodBase[]) match.Clone() : throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof (match));

etc etc 


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 20 Nov 2020, 10:12 AM

Hello Rafael,

Thanks for bringing this interesting case to our attention. Looking at the call stack, it seems that the expression used in the dynamic wrapper did not match any of the non-public methods of the target object. In order to provide you efficient support, we need to reproduce the issue in-house, for this purpose, I would like to ask you for some minimal sample which can be used for reproduction. You can also play with other types of non-public mocking APIs, just to make sure that the desired arrangement is possible. More about non-public mocking can be found in this documentation article.

I look forward to your reply, so we can plan further steps in resolving the issue.

Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at

General Discussions
Asked by
Top achievements
Rank 2
Answers by
Telerik team
Share this question