We have encountered some problem with the use of Rhino Mock in .Net
when trying to dynamically mock a generics interface that uses a
generic constraint.
Here is the interface definition:
public interface IClonable<TU>
{
T Clone<T>() where T : TU;
}
We’ve got an interface that derives from it that looks like :
public interface IObjectX: IClonable<IObjectX>
When I create this interface in rhino mocks
mocksRepository.DynamicMock<IObjectX>()
It crashes with the following error:
[...] tried to implicitly implement an interface method with weaker
type parameter constraints
If I remove the generic TU, or the constraint, it works but being a
framework class I'd rather for it to generate the error at compile
time instead of run time.
Are you aware of this problem and is there a way to avoid it or as it
been specifically fix in 3.5? We currently are using 3.4 and while
looking at your release notes for 3.5 it did not seem to be fixed.
Here is the actual stack leading to the error. It might be helpful to
you.
at System.Reflection.Emit.TypeBuilder._TermCreateClass(Int32 handle,
Module module)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
()
at
Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode
(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions
options)
at
Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options,
IInterceptor[] interceptors)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(Type theInterface, Type[] interfaces, IInterceptor[] interceptors)
at Rhino.Mocks.MockRepository.MockInterface(CreateMockState
mockStateFactory, Type type, Type[] extras)
at Rhino.Mocks.MockRepository.CreateMockObject(Type type,
CreateMockState factory, Type[] extras, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.DynamicMock<T>(Object[]
argumentsForConstructor)
Any help would be appreciated.
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---