CreateMock fails with an exception on Mono+Linux

8 views
Skip to first unread message

ryt...@gmail.com

unread,
Feb 5, 2007, 1:25:26 PM2/5/07
to Rhino.Mocks
Hi, all.

I've run into a problem trying to run NUnit tests where I mock things
using Rhino. The very first test that runs throws up in the SetUp part
and all subsequent test cases fail with an exception about trying to
create a class that already exists.

Here is the simplest code that causes the breakage:

using
NUnit.Framework;
using Rhino.Mocks;

[TestFixture]
public class Test {
public interface MyInterface {
void SomeMethod();
}

private MockRepository mocks;
private MyInterface mockedInstance;

[SetUp]
public void Setup() {
mocks = new MockRepository();
mockedInstance = mocks.CreateMock<MyInterface>();
}

[Test]
public void DoSomething() {
Assert.IsTrue(true);
}
}

and here is the result:

Test.DoSomething : System.ArgumentNullException : Argument cannot be
null.
Parameter name: method
at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
System.Reflection.MethodInfo method) [0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.MethodTokenExpression.Emit
(IEasyMember member, System.Reflection.Emit.ILGenerator gen)
[0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.MethodInvocationExpression.Emit
(IEasyMember member, System.Reflection.Emit.ILGenerator gen)
[0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.AssignStatement.Emit
(IEasyMember member, System.Reflection.Emit.ILGenerator gen)
[0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.AbstractCodeBuilder.Generate
(IEasyMember member, System.Reflection.Emit.ILGenerator il) [0x00000]
at Castle.DynamicProxy.Builder.CodeBuilder.EasyMethod.Generate ()
[0x00000]
at Castle.DynamicProxy.Builder.CodeBuilder.EasyProperty.Generate ()
[0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.EnsureBuildersAreInAValidState
() [0x00000]
at
Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.BuildType ()
[0x00000]
at
Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateType
() [0x00000]
at
Castle.DynamicProxy.Builder.CodeGenerators.InterfaceProxyGenerator.GenerateCode
(System.Type[] interfaces, System.Type targetType) [0x00000]
at
Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateInterfaceProxy
(System.Type[] interfaces, System.Type type) [0x00000]
at Castle.DynamicProxy.ProxyGenerator.CreateProxy (System.Type[]
interfaces, IInterceptor interceptor, System.Object target) [0x00000]
at Rhino.Mocks.MockRepository.MockInterface
(Rhino.Mocks.CreateMockState mockStateFactory, System.Type type,
System.Type[] extras) [0x00000]
at Rhino.Mocks.MockRepository.CreateMockObject (System.Type type,
Rhino.Mocks.CreateMockState factory, System.Type[] extras,
System.Object[] argumentsForConstructor) [0x00000]
at Rhino.Mocks.MockRepository.CreateMock[MyInterface]
(System.Object[] argumentsForConstructor) [0x00000]
at Test.Setup () [0x00000]
at <0x00000> <unknown method>
at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000]

Am running the latest stable Mono, the latest release of Rhino and
NUnit 2.2.8 on Ubuntu Feisty.

Thanks in advance. :)

-Lauri

Ayende Rahien

unread,
Feb 5, 2007, 3:23:51 PM2/5/07
to Rhino...@googlegroups.com
Interesting, it looks like it may be a difference of the mono Reflection.Emit engine and the MS one.
I don't have a mono install to test it, though, and I have no idea how to debug such issues on the mono platform.
The root issue seems to be in Dynamic Proxy, and that has underwent significant changes recently with the move to DP2.
I am currently (as time permits) trying to move to DP2, which hopefully won't have this issue.

ryt...@gmail.com

unread,
Feb 5, 2007, 4:04:50 PM2/5/07
to Rhino.Mocks
On Feb 5, 10:23 pm, "Ayende Rahien" <aye...@ayende.com> wrote:

> I don't have a mono install to test it, though, and I have no idea how to
> debug such issues on the mono platform.

I'd love to help debug it if I could, especially since it's either
that or move to another mock library. :(

> The root issue seems to be in Dynamic Proxy, and that has underwent
> significant changes recently with the move to DP2.
> I am currently (as time permits) trying to move to DP2, which hopefully
> won't have this issue.

I suppose I'll have to take this up with the Mono folks. Maybe they'll
come up with a solution. Actually, I'm fairly confident they'll fix it
in a future release, as they state that if something works on MS.Net
but not Mono, it's always a bug.

Thanks for taking the time to reply. And for writing a very nice mock
library. :)

-Lauri

Ayende Rahien

unread,
Feb 16, 2007, 2:25:10 PM2/16/07
to Rhino...@googlegroups.com
Okay, I am going to release Rhino Mocks 3.0 beta tomorrow, could you please give it a test on Mono and see whatever the issue is resolved?

ryt...@gmail.com

unread,
Feb 27, 2007, 7:42:56 AM2/27/07
to Rhino.Mocks
On Feb 16, 9:25 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> Okay, I am going to release Rhino Mocks 3.0 beta tomorrow, could you please
> give it a test on Mono and see whatever the issue is resolved?

Ok, I wrote the simplest test case I could think of:

using System;
using Rhino.Mocks;

public interface IFoo {
bool IsFoo { get; }
}

public class RhinoTest {
public static void Main(string[] args) {
MockRepository r = new MockRepository();
IFoo foo = r.CreateMock<IFoo>();
}
}

I compiled that with "gmcs -r:Rhino.Mocks.dll -target:winexe Test.cs"
and ran it. The result:

Unhandled Exception: System.ArgumentNullException: Argument cannot be


null.
Parameter name: method
at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
System.Reflection.MethodInfo method) [0x00000]
at

Castle.DynamicProxy.Generators.Emitters.SimpleAST.MethodTokenExpression.Emit
(IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
[0x00000]
at
Castle.DynamicProxy.Generators.Emitters.SimpleAST.AssignStatement.Emit
(IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
[0x00000]
at
Castle.DynamicProxy.Generators.Emitters.CodeBuilders.AbstractCodeBuilder.Generate
(IMemberEmitter member, System.Reflection.Emit.ILGenerator il)
[0x00000]
at
Castle.DynamicProxy.Generators.Emitters.ConstructorEmitter.Generate ()
[0x00000]
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersAreInAValidState
() [0x00000]
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
() [0x00000]
at
Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode
(System.Type proxyTargetType, System.Type[] interfaces,
Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
at
Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget
(System.Type theInterface, System.Type[] interfaces,
Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
(System.Type theInterface, System.Type[] interfaces,
Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(System.Type theInterface, System.Type[] interfaces,
Castle.DynamicProxy.ProxyGenerationOptions options,
Castle.Core.Interceptor.IInterceptor[] interceptors) [0x00000]
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(System.Type theInterface, System.Type[] interfaces,
Castle.Core.Interceptor.IInterceptor[] interceptors) [0x00000]


at Rhino.Mocks.MockRepository.MockInterface
(Rhino.Mocks.CreateMockState mockStateFactory, System.Type type,
System.Type[] extras) [0x00000]
at Rhino.Mocks.MockRepository.CreateMockObject (System.Type type,
Rhino.Mocks.CreateMockState factory, System.Type[] extras,
System.Object[] argumentsForConstructor) [0x00000]

at Rhino.Mocks.MockRepository.CreateMock[IFoo] (System.Object[]
argumentsForConstructor) [0x00000]
at RhinoTest.Main (System.String[] args) [0x00000]

I guess this really is a Mono bug then.

Please note that I didn't read any docs on 3.0, just tried to use it
like I've done so far. :)

Cheers!

-Lauri

Ayende Rahien

unread,
Feb 27, 2007, 8:30:47 AM2/27/07
to Rhino...@googlegroups.com
You shouldn't have to do anything special to run v3.0, so that is okay, I'll give it a test today and see what the problem is.

Ayende Rahien

unread,
Mar 12, 2007, 2:13:29 AM3/12/07
to Rhino...@googlegroups.com
Sorry for the long time it took.
Just run the tests on Mono Win32, and it certainly failed.
I pinged the mono group, we will see what they have to say about it.

Ayende Rahien

unread,
Mar 16, 2007, 4:56:18 PM3/16/07
to Rhino...@googlegroups.com
Okay, I just got a response from the Mono team.
This is a two part answer:
The API that Dynamic Proxy is using for generating some of its proxies is missing from Rhino Mocks.
I can provide a version of Rhino Mocks that will (probably) run on Mono, but it will be limited (no generic methods support, for instance).
Until such time that Mono support this api (FWIW, GetMethodFromHandle(RuntimeMethodHandle, RuntimeTypeHandle) )
I open a bug about it here:
http://bugzilla.ximian.com/show_bug.cgi?id=81169

Until it is fixed, I suggest trying to use Rhino Mocks 2.9.6 for mocking on mono

Stefan Podskubka

unread,
May 10, 2007, 4:22:58 PM5/10/07
to Rhino.Mocks
I just ran into the same issue when trying to run my unit tests on
Mono 1.2.3.1 and found this post here.
Then I looked at your bug report and found this:
http://bugzilla.ximian.com/show_bug.cgi?id=78637

The issue seems to be resolved, now we Mono (or .NET/Mono) developers
just need to wait for Mono 1.2.4, which should be released in the near
future and hopefully contains this fix.

> > > > Castle.DynamicProxy.Generators.Emitters.SimpleAST.MethodTokenExpression.Emi­t


> > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > > > [0x00000]
> > > > at
> > > > Castle.DynamicProxy.Generators.Emitters.SimpleAST.AssignStatement.Emit
> > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > > > [0x00000]
> > > > at
>

> > > > Castle.DynamicProxy.Generators.Emitters.CodeBuilders.AbstractCodeBuilder.Ge­nerate


> > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator il)
> > > > [0x00000]
> > > > at
> > > > Castle.DynamicProxy.Generators.Emitters.ConstructorEmitter.Generate ()
> > > > [0x00000]
> > > > at
>

> > > > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersA­reInAValidState


> > > > () [0x00000]
> > > > at
> > > > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
> > > > () [0x00000]
> > > > at
>

> > > > Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCo­de


> > > > (System.Type proxyTargetType, System.Type [] interfaces,
> > > > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > > at
>

> > > > Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarg­et

> > > > -Lauri- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Ayende Rahien

unread,
May 10, 2007, 4:37:46 PM5/10/07
to Rhino...@googlegroups.com
thanks for the follow up, any idea about 1.2.4?

Stefan Podskubka

unread,
May 10, 2007, 5:04:22 PM5/10/07
to Rhino.Mocks
Well, I don't know exactly what the timeframe is, but in this message
from the [Mono-dev] mailing list which was posted 21 Apr 2007 a link
to available preview packages and release-notes is mentioned.
Haven't tried Rhino Mocks with the preview yet, but since the bug
report was closed on 08 May 2007 I am not sure if the fix is already
in the preview release...

http://lists.ximian.com/pipermail/mono-devel-list/2007-April/023196.html

I'll let you know if it works when I have time to try the 1.2.4
preview release.

On 10 Mai, 22:37, "Ayende Rahien" <aye...@ayende.com> wrote:
> thanks for the follow up, any idea about 1.2.4?
>

> > > - Zitierten Text anzeigen -- Zitierten Text ausblenden -

Ayende Rahien

unread,
May 10, 2007, 5:05:46 PM5/10/07
to Rhino...@googlegroups.com
cool, looking forward to it.

> > Castle.DynamicProxy.Generators.Emitters.SimpleAST.MethodTokenExpression.Emi限t

> > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > > > > > [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.Generators.Emitters.SimpleAST.AssignStatement.Emit
> > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > > > > > [0x00000]
> > > > > >   at
>
> > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator il)
> > > > > > [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.Generators.Emitters.ConstructorEmitter.Generate ()
> > > > > > [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersA限reInAValidState

> > > > > > () [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
> > > > > > () [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCo限de

> > > > > > (System.Type proxyTargetType, System.Type [] interfaces,
> > > > > > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarg限et

> > > > > > (System.Type theInterface, System.Type [] interfaces,
> > > > > > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
> > > > > > (System.Type theInterface, System.Type[] interfaces,
> > > > > > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > > > > > (System.Type theInterface, System.Type[] interfaces,
> > > > > > Castle.DynamicProxy.ProxyGenerationOptions options,
> > > > > > Castle.Core.Interceptor.IInterceptor [] interceptors) [0x00000]
> > > > > >   at
>
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > > > > > (System.Type theInterface, System.Type[] interfaces,
> > > > > > Castle.Core.Interceptor.IInterceptor[] interceptors) [0x00000]
> > > > > >   at Rhino.Mocks.MockRepository.MockInterface
> > > > > > (Rhino.Mocks.CreateMockState mockStateFactory, System.Type type,
> > > > > > System.Type[] extras) [0x00000]
> > > > > >   at Rhino.Mocks.MockRepository.CreateMockObject (System.Typetype,
> > > > > > Rhino.Mocks.CreateMockState factory, System.Type[] extras,
> > > > > > System.Object[] argumentsForConstructor) [0x00000]
> > > > > >   at Rhino.Mocks.MockRepository.CreateMock[IFoo] (System.Object[]
> > > > > > argumentsForConstructor) [0x00000]
> > > > > >   at RhinoTest.Main ( System.String[] args) [0x00000]

Stefan Podskubka

unread,
May 10, 2007, 5:29:46 PM5/10/07
to Rhino.Mocks
Ok, the answer is it does NOT work with the available preview release
for win32 (the release notes of the installer say it is from 30 April
2007).

But, instead of the ArgumentNullException now the following exception
is thrown: "System.NotImplementedException : The requested feature is
not implemented."

On 10 Mai, 23:05, "Ayende Rahien" <aye...@ayende.com> wrote:
> cool, looking forward to it.
>

> > > > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGeneratorgen)


> > > > > > > > [0x00000]
> > > > > > > >   at
>
> > > > Castle.DynamicProxy.Generators.Emitters.SimpleAST.AssignStatement.Emit
> > > > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGeneratorgen)
> > > > > > > > [0x00000]
> > > > > > > >   at
>

> > Castle.DynamicProxy.Generators.Emitters.CodeBuilders.AbstractCodeBuilder.Ge­限nerate


> > > > > > > > (IMemberEmitter member, System.Reflection.Emit.ILGenerator il)
> > > > > > > > [0x00000]
> > > > > > > >   at
>
> > > > Castle.DynamicProxy.Generators.Emitters.ConstructorEmitter.Generate ()
> > > > > > > > [0x00000]
> > > > > > > >   at
>

> > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersA­限reInAValidState


> > > > > > > > () [0x00000]
> > > > > > > >   at
>
> > > > Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
> > > > > > > > () [0x00000]
> > > > > > > >   at
>

> > Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCo­限de


> > > > > > > > (System.Type proxyTargetType, System.Type [] interfaces,
> > > > > > > > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > > > > > >   at
>

> > Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarg­限et

> > > > > > > > argumentsForConstructor) [0x00000]
> > > > > > > >   at RhinoTest.Main (System.String[] args) [0x00000]

Stefan Podskubka

unread,
May 16, 2007, 4:26:16 AM5/16/07
to Rhino.Mocks
Ok, so Mono 1.2.4 was released yesterday, but sadly the needed
implementations didn't make it into the final release either, still
the same result as with the preview release.
Looks like we still have to wait a little bit longer for RhinoMocks
becoming Mono compatible again, but I'm looking forward to it!
Reply all
Reply to author
Forward
0 new messages