Moq 1.51 error: A matching constructor for the given arguments was not found on the mocked type.

718 views
Skip to first unread message

Geoff Taylor

unread,
Feb 25, 2008, 5:07:16 AM2/25/08
to moq...@googlegroups.com

Hi there,

 

I've just upgraded to 1.51 (previously I was on version 1.2), and I've just started getting the following error:

                "A matching constructor for the given arguments was not found on the mocked type."

 

The stack trace is:

System.MissingMethodException: Constructor on type 'System.Web.Hosting.VirtualPathProvider' not found.

at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttrBinder binderObject[] argsCultureInfo cultureObject[] activationAttributes)
at
System.Activator.CreateInstance(Type typeBindingFlags bindingAttrBinder binderObject[] argsCultureInfo cultureObject[] activationAttributes)
at
Moq.RemotingProxy..ctor(Type targetTypeAction`1 interceptorObject[] ctorArgs)
at
Moq.Mock`1..ctor(MockBehavior behaviorObject[] args)

System.ArgumentException: A matching constructor for the given arguments was not found on the mocked type.

at Moq.Mock`1..ctor(MockBehavior behaviorObject[] args)
at
Moq.Mock`1..ctor()
at
OpinionatedGeek.Applications.Tests.PathTests.GetVirtualPathProviderMock()

 

My code, which hasn't changed for 1.51, is pretty simple:

 

        private static Mock<VirtualPathProvider> GetVirtualPathProviderMock ()

        {

            return new Mock<VirtualPathProvider> (MockBehavior.Strict);

        }

 

My guess (from a brief look at the Moq code) is that it's because VirtualPathProvider is both abstract and MarshalByRefObject.

 

So, is this a bug in Moq or am I doing something wrong?

 

Many thanks,

 

                                                Geoff

Geoff

unread,
Feb 25, 2008, 5:10:36 AM2/25/08
to Moq Discussions
On Feb 25, 10:07 am, "Geoff Taylor" <ge...@opinionatedgeek.com> wrote:
>
> My guess (from a brief look at the Moq code) is that it's because
> VirtualPathProvider is both abstract and MarshalByRefObject.

I meant to say that my guess is that's because it's abstract,
MarshalByRefObject, and has a protected constructor instead of a
public one.

Geoff

Daniel Cazzulino

unread,
Feb 25, 2008, 2:36:16 PM2/25/08
to moq...@googlegroups.com
Mmm... good point...
I guess in this case you'd want the interception to be based on a combination of a class derived from the given class (so that the protected ctor is not an issue) AND remoting interception so that you can mock/expect on non-virtual members...

Geoff Taylor

unread,
Feb 27, 2008, 8:38:28 AM2/27/08
to moq...@googlegroups.com

Yep, I think that's the 'right' answer (although it's overkill for my current situation).

 

Cheers,

 

                                                Geoff

Daniel Cazzulino

unread,
Mar 8, 2008, 1:09:43 PM3/8/08
to moq...@googlegroups.com
strange thing is that apparently it worked before?

could you create a new Issue so that we can properly track it and fix it for the next major release? (http://code.google.com/p/moq/issues/list)

Geoff Taylor

unread,
Mar 8, 2008, 1:57:36 PM3/8/08
to moq...@googlegroups.com

Hi,

 

Wasn't sure if you wanted an issue raised or not.  It's done now (with some simple sample code) at:

                http://code.google.com/p/moq/issues/detail?id=14

Daniel Cazzulino

unread,
Mar 9, 2008, 7:27:45 AM3/9/08
to moq...@googlegroups.com
Awesome. Just set it to Accepted as I know this doesn't work :(

Thanks for the report!
Reply all
Reply to author
Forward
0 new messages