"Cannot Instantiate Proxy of Class ... Could not find a constructor that would match"

8,719 views
Skip to first unread message

Kevin

unread,
May 12, 2011, 11:50:15 AM5/12/11
to Moq Discussions
Hello -

First off, thanks to the folks who created Moq. It makes my life a lot
easier.

Here's my issue: I can create a new object using:

>obj A = new obj(parameter1, parameter2);

But when I attempt to create a new object via Moq:

>var objMock = new Mock<obj>(parameter1, parameter2), this exception occurs:

"Cannot Instantiate Proxy of Class ... Could not find a constructor
that would match"

I had created another object, "obj2," in the exact same fashion above.
In other words, I was able to "new" an object, then mock it like the
code above with success. However, in my current case, I cannot.

Thanks,
Kevin

Daniel Cazzulino

unread,
May 12, 2011, 11:56:12 AM5/12/11
to moq...@googlegroups.com

Code?

/kzu from Android

Kevin

unread,
May 12, 2011, 12:06:32 PM5/12/11
to Moq Discussions
Actually, I just figured it out!

Turns out I was passing in the wrong parameters.

Example:

class Object
{
public Object(string name, int age, double weight)
{
...
}
}

When I tried to mock Object, I did:

>var objectMock = new Mock<Object>(null, 0, 0)

figuring that the "0" for weight would get cast to a double. However,
the cast never occurred, so I had passed in an "int" rather than a
"double," causing the problem.



On May 12, 11:56 am, Daniel Cazzulino <k...@clariusconsulting.net>
wrote:
> Code?
>
> /kzu from Android
> > Unsubscribe: moqdisc-u...@googlegroups.com- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages