Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:43:50+00:00 2026-05-23T19:43:50+00:00

Totally simple situation, but I can’t make it work. I am running into an

  • 0

Totally simple situation, but I can’t make it work. I am running into an issue with using Moq to mock a generic method (in this case, on a Ninject Kernel interface):

T Get<T>();

I set up my mock object:

Mock<IKernel> mockKernel = new Mock<IKernel>();
        mockKernel.Setup(x => x.Get<IGetUserQuery>()).Returns(new GetUserQuery());

At runtime I get the following exception:

Expression references a method that does not belong to the mocked object: x => x.Get<IGetUserQuery>(new[] {  })

Any idea why it’s throwing this? I’ve mocked generics in Moq before without a problem… are there cases in which generic mocking isn’t supported? This seems like a straightforward case. The only wrinkle is that IGetUserQuery in turn inherits from a genericized type:

IGetUserQuery : ICommand<UserQueryInput, UserQueryOutput>

I don’t see this creating a problem because the generic types for this implementation of ICommand are staticly defined by IGetUserQuery, so I doubt this is confusing Moq.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:43:51+00:00Added an answer on May 23, 2026 at 7:43 pm

    The problem is that T Get<T> () isn’t actually a method defined in the IKernel interface, it is an extension method defined here.

    Why are you trying to mock T Get<T> () in the first place? Interaction with the IoC container should be absolutely minimal, usually just at the toplevel “entry point” to your system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running into a situation using the Entity Framework (EF) that has me totally
This should be totally simple but I can't get it working no matter what
I've written a simple django app to test ImageField, but I'm running into problem
Maybe i'm totally outdated but for last four years i've been using simple FTP
I am totally new to XSLT and can't work out where I am going
This may be a simple problem. But im totally stuck with this error. I
I have a really simple jQuery problem (I guess). But im totally new to
I am working on a simple invoicing and accounting applications, but I am totally
I must be missing something simple, but I can't see it. First, the setup:
Today I started to learn iPhone simple animations, but I was totally Confused about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.