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

Cannot set instance to null #5

Open
sgtHoloToaster opened this issue Sep 20, 2021 · 0 comments
Open

Cannot set instance to null #5

sgtHoloToaster opened this issue Sep 20, 2021 · 0 comments

Comments

@sgtHoloToaster
Copy link
Owner

sgtHoloToaster commented Sep 20, 2021

An exception is thrown when trying to create an instance which has a dependency set to null:

var mocker = new AutoMoqer();
mocker.SetInstance<SomeDependency>(null);
mocker.Create<SomeClassWithSomeDependency>(); // here the exception is thrown

Exception details:

Message: 
    Castle.DynamicProxy.InvalidProxyConstructorArgumentsException : Can not instantiate proxy of class: ZTool.Data.DataContext.
    Could not find a parameterless constructor.
  Stack Trace: 
    ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
    ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
    CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments) line 62
    Mock`1.InitializeInstance() line 311
    Mock`1.OnGetObject() line 325
    Mock.get_Object() line 179
    AutoMoqer.<GetParameters>b__9_0(ParameterInfo p)
    SelectArrayIterator`2.ToArray()
    Enumerable.ToArray[TSource](IEnumerable`1 source)
    AutoMoqer.GetParameters(ConstructorInfo constructor)
    AutoMoqer.Create(Type type)
    AutoMoqer.Create[T]()
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

1 participant