You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Trying to configure/override a generic overridden virtual method with an out parameter on a class substitute throws an exception.
System.ArgumentException : Could not find method overriding Boolean TryCreateControl[TResult](IBaseControl, IHasGridLinesDefined, TResult ByRef) on type MyControlFactory. This is most likely a bug. Please report it.
at Castle.DynamicProxy.Internal.InvocationHelper.ObtainMethod(MethodInfo proxiedMethod, Type type)
at Castle.Core.Internal.SynchronizedDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Castle.DynamicProxy.Internal.InvocationHelper.GetMethodOnType(Type type, MethodInfo proxiedMethod)
at NSubstitute.Proxies.CastleDynamicProxy.CastleInvocationMapper.Map(IInvocation castleInvocation)
at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.MyControlFactoryProxy.TryCreateControl[TResult](IBaseControl control, IHasGridLinesDefined parentGrid, TResult& result)
To Reproduce
given:
publicinterfaceIControlFactory{boolTryCreateControl<TResult>(IBaseControlcontrol,IHasGridLinesDefined?parentGrid,[MaybeNullWhen(false)]outTResultresult);}publicclassControlFactory:IControlFactory{publicvirtualboolTryCreateControl<TResult>(IBaseControlcontrol,IHasGridLinesDefined?parentGrid,[MaybeNullWhen(false)]outTResultresult){/* ... */}}publicclassMyControlFactory:ControlFactory{// If this override is removed, code runs as expectedpublicoverrideboolTryCreateControl<TResult>(IBaseControlcontrol,IHasGridLinesDefined?parentGrid,[MaybeNullWhen(false)]outTResultresult){/* ... */}}[Test]voidMyTest(){varcontrol= Substitute.For<IStringTextBoxControl>();varcontrolFactory= Substitute.For<MyControlFactory>();
controlFactory.Configure().TryCreateControl<object>(default,default,outvar _).ReturnsForAnyArgs(ci =>{ ci[2]=control;returntrue;});// <== exception here}
Expected behaviour
Runs normally and the method returns the desired object when called
Environment:
NSubstitute version: 5.0.0
NSubstitute.Analyzers version: CSharp 1.0.16
Platform: .NET Framework 4.8
Additional context
This might be a bug in Castle.Core or wrong usage of it, but I can't tell.
If the method override in the MyControlFactory class is removed, the exception does not occur and code runs as expected
The text was updated successfully, but these errors were encountered:
See referenced issue in Caste.Core. I guess whenever they release a version that includes the fix, I can just use the updated Casle.Core version to resolve the problem.
Describe the bug
Trying to configure/override a generic overridden virtual method with an out parameter on a class substitute throws an exception.
To Reproduce
given:
Expected behaviour
Runs normally and the method returns the desired object when called
Environment:
Additional context
This might be a bug in Castle.Core or wrong usage of it, but I can't tell.
If the method override in the MyControlFactory class is removed, the exception does not occur and code runs as expected
The text was updated successfully, but these errors were encountered: