I get the generic message below when mocking "autoMocker.CreateInstance<HeliumController>();" with Moq.AutoMock.Automocker. The HeliumController class's constructor take several interfaces. How can I find which specific interface or constructor is failing to mock?
{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NotSupportedException: Type to mock must be an interface, a delegate, or a non-sealed, non-static class.
at Moq.Guard.IsMockable(Type type)
at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
at Moq.Mock`1..ctor(MockBehavior behavior)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Moq.AutoMock.Resolvers.MockResolver.Resolve(MockResolutionContext context)
at Moq.AutoMock.AutoMocker.Resolve(Type serviceType, Object initialValue)
at Moq.AutoMock.AutoMocker.Resolve(Type serviceType)
at Moq.AutoMock.AutoMocker.Get(Type serviceType)
at Moq.AutoMock.AutoMocker.<CreateArguments>b__58_0(ParameterInfo x)
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Moq.AutoMock.AutoMocker.CreateArguments(Type type, BindingFlags bindingFlags)
at Moq.AutoMock.AutoMocker.CreateInstance(Type type, Boolean enablePrivate)
at Moq.AutoMock.AutoMocker.CreateInstance[T](Boolean enablePrivate)
at Moq.AutoMock.AutoMocker.CreateInstance[T]()
at Helium.Api.Tests.API.v2.HeliumControllerSearchTests..ctor()
In my case,
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
can solve this issue.