mocking internal classes fails with Rhino Mocks 3.0 beta 3

68 views
Skip to first unread message

Tim Noll

unread,
Feb 27, 2007, 5:28:35 AM2/27/07
to Rhino...@googlegroups.com
Hi,

In order to mock internal classes, this previously worked for me with
Rhino Mocks 2:

[assembly: InternalsVisibleTo("DynamicAssemblyProxyGen")]

However, with Rhino Mocks 3.0 beta 3, it throws this exception:

Castle.DynamicProxy.Generators.GeneratorException : Type is not
public, so a proxy cannot be generated. Type:
----.----.---.-------------.MemberAssembler
at Castle.DynamicProxy.DefaultProxyBuilder.AssertValidType(Type target)
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.CreateMock[T](Object[] argumentsForConstructor)

I noticed that RhinoMocks.StrongName had changed, so I tried changing
the name of the dynamic assembly like this, but it still fails:

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

Any suggestions, or is this a bug?

Regards,

Tim

Ayende Rahien

unread,
Feb 27, 2007, 8:35:52 AM2/27/07
to Rhino...@googlegroups.com
Please use RhinoMocks.StrongName,
Or replace the "DynamicProxyGenAssembly2" with:
DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7

On 2/27/07, Tim Noll <tim....@gmail.com> wrote:

Hi,

In order to mock internal classes, this previously worked for me with
Rhino Mocks 2:

[assembly: InternalsVisibleTo("DynamicAssemblyProxyGen")]

However, with Rhino Mocks 3.0 beta 3, it throws this exception:

Castle.DynamicProxy.Generators.GeneratorException : Type is not
public, so a proxy cannot be generated. Type:
----.----.---.-------------.MemberAssembler
        at Castle.DynamicProxy.DefaultProxyBuilder.AssertValidType (Type target)

Tim Noll

unread,
Feb 27, 2007, 10:32:29 AM2/27/07
to Rhino...@googlegroups.com
Ayende,

I've tried both of these options, and the same exception is still thrown.

Tim

Ayende Rahien

unread,
Feb 27, 2007, 10:39:11 AM2/27/07
to Rhino...@googlegroups.com
Can you send me a reproduction?

Tim Noll

unread,
Feb 27, 2007, 11:37:41 AM2/27/07
to Rhino...@googlegroups.com
Yes, I'll try to do so later today.

Tim Noll

unread,
Feb 27, 2007, 12:35:35 PM2/27/07
to Rhino...@googlegroups.com
Ayende,

This small test fixture will reproduce the issue. I have confirmed
that this succeeds under version 2.9.6.40380, using the assembly name
string "DynamicAssemblyProxyGen". However, it fails under 3.0.486.0,
even when using the full strong name string or RhinoMocks.StrongName.


using System.Runtime.CompilerServices;
using NUnit.Framework;
using Rhino.Mocks;

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

internal class InternalClass
{
}

[TestFixture]
public class InternalClassMockingFixture
{
[Test]
public void MockInternalClass()
{
MockRepository mocker = new MockRepository();
InternalClass mockInternalClass = mocker.CreateMock<InternalClass>();

Assert.IsNotNull(mockInternalClass);
}
}


Regards,

Tim

Ayende Rahien

unread,
Mar 5, 2007, 10:21:02 PM3/5/07
to Rhino...@googlegroups.com
Interesting bug, turned out that I only had tests for NESTED internal types.
Fixed, thanks.

On 2/27/07, Tim Noll < tim....@gmail.com> wrote:

Ayende,

Stefan

unread,
Apr 10, 2007, 4:31:31 AM4/10/07
to Rhino.Mocks
Ayende,

I am using the current version of RhinoMocks (3.0.1) and I ran into
the same Problem as Tim, except with internal interfaces.
The following is like Tim's above sample code, only modified to
feature an internal interface instead of an internal class.
I am compiling a strong named assembly.

using System.Runtime.CompilerServices;
using NUnit.Framework;
using Rhino.Mocks;

[assembly: InternalsVisibleTo(RhinoMocks.StrongName)]

namespace RhinoException
{
internal interface IInternalInterface { }

[TestFixture]
public class InternalClassMockingFixture
{
[Test]
public void MockInternalClass()
{
MockRepository mocker = new MockRepository();

IInternalInterface mockInternalInterface =
mocker.CreateMock<IInternalInterface>();

Assert.IsNotNull(mockInternalInterface);
}
}
}

The following exception is thrown:
RhinoException.InternalClassMockingFixture.MockInternalClass :
System.TypeLoadException : Type
'IInternalInterfaceProxyf155e4bf2d2c49a59a1166c7ed500a68' from
assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' is attempting to implement an inaccessible
interface.

If I don't compile a strong named assembly and replace the
RhinoMocks.StrongName with "DynamicProxyGenAssembly2", it works.

On 6 Mrz., 05:21, "Ayende Rahien" <aye...@ayende.com> wrote:
> Interesting bug, turned out that I only had tests for NESTED internal types.
> Fixed, thanks.
>

> On 2/27/07, Tim Noll <tim.n...@gmail.com> wrote:
>
>
>
> > Ayende,
>
> > This small test fixture will reproduce the issue. I have confirmed
> > that this succeeds under version 2.9.6.40380, using the assembly name
> > string "DynamicAssemblyProxyGen". However, it fails under 3.0.486.0,
> > even when using the full strong name string or RhinoMocks.StrongName.
>
> > using System.Runtime.CompilerServices;
> > using NUnit.Framework;
> > using Rhino.Mocks;
>
> > [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
>
> > internal class InternalClass
> > {
> > }
>
> > [TestFixture]
> > public class InternalClassMockingFixture
> > {
> > [Test]
> > public void MockInternalClass()
> > {
> > MockRepository mocker = new MockRepository();
> > InternalClass mockInternalClass = mocker.CreateMock
> > <InternalClass>();
>
> > Assert.IsNotNull(mockInternalClass);
> > }
> > }
>
> > Regards,
>
> > Tim
>

> > On 27/02/07, Tim Noll <tim.n...@gmail.com> wrote:
> > > Yes, I'll try to do so later today.
>
> > > Tim
>
> > > On 27/02/07, Ayende Rahien <aye...@ayende.com> wrote:
> > > > Can you send me a reproduction?
>

> > > > On 2/27/07, Tim Noll <tim.n...@gmail.com> wrote:
>
> > > > > Ayende,
>
> > > > > I've tried both of these options, and the same exception is still
> > thrown.
>
> > > > > Tim
>
> > > > > On 27/02/07, Ayende Rahien <aye...@ayende.com> wrote:
> > > > > > Please use RhinoMocks.StrongName,
> > > > > > Or replace the "DynamicProxyGenAssembly2" with:
> > > > > > DynamicProxyGenAssembly2,
>
> > PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7
>

Ayende Rahien

unread,
Apr 10, 2007, 4:39:31 AM4/10/07
to Rhino...@googlegroups.com
Hm, this looks like I am not handing the case of unsigned correctly.
The work around, as you have mentioned, is to use signed tests, and I'll fix it shortly.

assembly 'DynamicProxyGenAssembly2, Version= 0.0.0.0, Culture=neutral,

Stefan

unread,
Apr 10, 2007, 5:13:45 AM4/10/07
to Rhino.Mocks
Actually, it's the other way around.
It does work with unsigned assemblies.
The problem exists when using signed (strong named) assemblies.

But I think we both mean the same thing :)

On 10 Apr., 10:39, "Ayende Rahien" <aye...@ayende.com> wrote:
> Hm, this looks like I am not handing the case of unsigned correctly.
> The work around, as you have mentioned, is to use signed tests, and I'll fix
> it shortly.
>

> > assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,

David Mann

unread,
Apr 12, 2007, 10:12:59 AM4/12/07
to Rhino.Mocks
When you solve this problem can you test with unsigned, delayed
signed, and signed assemblies?
I am just concerned that delayed signing may cause additional
complication...

Dave

On Apr 10, 3:39 am, "Ayende Rahien" <aye...@ayende.com> wrote:
> Hm, this looks like I am not handing the case of unsigned correctly.
> The work around, as you have mentioned, is to use signed tests, and I'll fix
> it shortly.
>

> > assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,

> > PublicKey=0024000004800000940000000602000000240000525341310004000001000100c­547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93­bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64b­cb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e1­13be11e6a7d3113e92484cf7045cc7

> > > > > > > > > Tim- Hide quoted text -
>
> - Show quoted text -

Ayende Rahien

unread,
Apr 28, 2007, 7:54:26 PM4/28/07
to Rhino...@googlegroups.com
That wasn't fun. The issue only appear when you try to mock an internal interface, not an internal class.
Fixed, thanks.

On 4/12/07, David Mann < da...@dmsquared.com> wrote:

When you solve this problem can you test with unsigned, delayed
signed, and signed assemblies?
I am just concerned that delayed signing may cause additional
complication...

Dave

On Apr 10, 3:39 am, "Ayende Rahien" < aye...@ayende.com> wrote:
> Hm, this looks like I am not handing the case of unsigned correctly.
> The work around, as you have mentioned, is to use signed tests, and I'll fix
> it shortly.
>
> On 4/10/07, Stefan <s.podsku...@hcs.at> wrote:
>
>
>
>
>
> > Ayende,
>
> > I am using the current version of RhinoMocks ( 3.0.1) and I ran into

> > the same Problem as Tim, except with internal interfaces.
> > The following is like Tim's above sample code, only modified to
> > feature an internal interface instead of an internal class.
> > I am compiling a strong named assembly.
>
> > using System.Runtime.CompilerServices;
> > using NUnit.Framework;
> > using Rhino.Mocks;
>
> > [assembly: InternalsVisibleTo( RhinoMocks.StrongName)]
>
> > namespace RhinoException
> > {
> >     internal interface IInternalInterface { }
>
> >     [TestFixture]
> >     public class InternalClassMockingFixture
> >     {
> >         [Test]
> >         public void MockInternalClass()
> >         {
> >             MockRepository mocker = new MockRepository();
> >             IInternalInterface mockInternalInterface =
> > mocker.CreateMock<IInternalInterface>();
>
> >             Assert.IsNotNull(mockInternalInterface);
> >         }
> >     }
> > }
>
> > The following exception is thrown:
> > RhinoException.InternalClassMockingFixture.MockInternalClass :
> > System.TypeLoadException : Type
> > 'IInternalInterfaceProxyf155e4bf2d2c49a59a1166c7ed500a68' from
> > assembly 'DynamicProxyGenAssembly2, Version= 0.0.0.0, Culture=neutral,
Reply all
Reply to author
Forward
0 new messages