interface IExtensible<T>
{
void AddAll<U>(IEnumerable<U> stuff) where U : T;
}
I implement this in a class that I am trying to test, but in mocking
it, I am getting the following exception while running the test:
"""
Message:Method 'AddAll' on type
'IExtensible`1Proxy8f0350fd5bde40b0928d2a70a8c4edf2' from assembly
'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' tried to implicitly override a method with weaker
type parameter constraints.
Source:mscorlib
TypeName:IExtensible`1Proxy8f0350fd5bde40b0928d2a70a8c4edf2
TargetSite:System.Type TermCreateClass(Int32,
System.Reflection.Module)
HelpLink:null
StackTrace:
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.ClassProxyGenerator.GenerateCode(Type[]
interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(Type
theClass, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type
baseClass, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type
targetType, Type[] interfaces, ProxyGenerationOptions options,
Object[] constructorArgs, IInterceptor[] interceptors)
at Rhino.Mocks.MockRepository.MockClass(CreateMockState
mockStateFactory, Type type, Type[] extras, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.CreateMockObject(Type type,
CreateMockState factory, Type[] extras, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMultiMock(Type type, Type[]
extraTypes, Object[] argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMock(Type type, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMock[T](Object[]
argumentsForConstructor)
at KeyedCollections.UnitTests.KeyedCollectionBaseFixture.SetUp() in
f:\C5\KeyedCollections\KeyedCollections\UnitTests
\KeyedCollectionBaseFixture.cs:line 37
"""
Line 37 is:
mockedPairs = Mocks.DynamicMock<IExtensible<KeyValuePair<Key,
Record>>>();
Am I doing something incorrectly? Thanks for your help.
I think this is the same issue that is already discussed here:
http://groups.google.com/group/RhinoMocks/browse_thread/thread/69fca6bd6dba071f/c9429d7f8060c107?hl=en#c9429d7f8060c107
Stefan
On Sep 6, 9:56 am, Stefan Podskubka <s.podsku...@hcs.at> wrote:
> Marcus,
>
> I think this is the same issue that is already discussed here:http://groups.google.com/group/RhinoMocks/browse_thread/thread/69fca6...
> >> Am I doing something incorrectly? Thanks for your help.- Hide quoted text -
>
> - Show quoted text -
> > - Show quoted text -- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -
It looks like Microsoft is closing it as "As Design".
http://connect.microsoft.com/VisualStudio/feedback/SearchResults.aspx?SearchQuery=+tried+to+implicitly+implement+an+interface+method+with+weaker+type+parameter+constraints
On 6 Sep., 22:19, Marcus Griep < neoeinst...@gmail.com> wrote:
> Thanks.
>
> On Sep 6, 9:56 am, Stefan Podskubka <s.podsku...@hcs.at> wrote:
>
>
>
> > Marcus,
>
> > I think this is the same issue that is already discussed here:http://groups.google.com/group/RhinoMocks/browse_thread/thread/69fca6. ..
>
> > Stefan
>
> > Marcus Griep wrote:
> > > Sorry, the PartialMocks in the StackTrace are from a prior run on the
> > > abstract class; I tried mocking the interface with dynamic and regular
> > > mocks as well as stubs and got the same error.
>
> > > On Sep 6, 12:54 am, Marcus Griep <neoeinst...@gmail.com> wrote:
> > >> I am using the C5 generics library and there are a couple of methods
> > >> within the interfaces similar to below:
>
> > >> interface IExtensible<T>
> > >> {
> > >> void AddAll<U>(IEnumerable<U> stuff) where U : T;
>
> > >> }
>
> > >> I implement this in a class that I am trying to test, but in mocking
> > >> it, I am getting the following exception while running the test:
> > >> """
> > >> Message:Method 'AddAll' on type
> > >> 'IExtensible`1Proxy8f0350fd5bde40b0928d2a70a8c4edf2' from assembly
> > >> 'DynamicProxyGenAssembly2, Version= 0.0.0.0, Culture=neutral,
> > >> at Rhino.Mocks.MockRepository.PartialMultiMock (Type type, Type[]
No, this is just a C# compiler bug I found in passing when
investigating the problem after Ayende had reported it to the Castle
group. That's the bug I opened for the actual problem:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290313
It seems to be fixed in Orcas and the upcoming .NET 2.0 service pack.
Also, as I've found out, "Closed By Design" doesn't necessarily mean
the bug won't be fixed, it might just be fixed in another place.
Still, Connect communication from MS to the bug reporter sucks most of
the time. It's really disappointing to see a bug closed without any
(reasonable) comment after you've spent some time writing the bug
report.
Fabian
To clafirfy, it's either a compiler bug or a verifier bug. However,
it's not really the same as the RhinoMocks problem.
The original bug is in DynamicProxy and occurrs when overriding or
implementing generic methods with type constraints that refer to the
type parameters of the declaring class. DynamicProxy uses the wrong
type parameters, leading to the "weak type parameter constraints"
exception.
Ayende created a patch fixing this, but this led to another exception:
System.Security.VerificationException : Method
Castle.DynamicProxy.Tests.GenericTestInterface`1
[System.Collections.ObjectModel.Collection`1[System.String]].GenericTestMethod:
type argument 'T2' violates the constraint of type parameter 'T2'.
And that's a CLR bug related to the ldtoken IL instruction. I reported
that one here:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290313
And it will be fixed in the upcoming service pack (together with a few
other issues we found with DynamicProxy).
See also the Castle group:
http://groups.google.com/group/castle-project-devel/browse_thread/thread/1697e02d96c9c2df/8f1969c2267e35d8
Fabian
Just for the record, the compiler or verifier bug has actually been
reexamined and reopened. While it's not a RhinoMocks-related bug, it's
still nice to see it get some attention after all. Maybe this was
because a few people here seem to have voted on it, or maybe someone's
read Ayende's blog :)
Fabian