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

  • SEARCH
  • Home
  • 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 8504939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:10:42+00:00 2026-06-11T02:10:42+00:00

OK, I am baffled at this point. Moq is not calling my one method,

  • 0

OK, I am baffled at this point. Moq is not calling my one method, yet the assert on verify does show it is calling all my other methods that are not parameterless. I have even added the following:

.Throws<Exception>()

just to see if it would even throw, and still nothing (but adding it to other methods works). I know the object being used is my mock because I added a call that IS being logged immediately after the call that is not.

The method name is Finalize(). I doubt the naming of the method is the problem, but I have tried everything else.

Code After simplifying down to simplest solution by making the main method public:

  var asyncRecognizerMock = new Mock<AsyncRecognizer>();
  var asyncRecognizerFactoryMock = new Mock<AsyncRecognizerFactory>();
  var trainerMock = new Mock<Trainer>();
  trainerMock.Setup(trainer => trainer.Finalize()).Verifiable();
  var trainerDataRepository = new TrainerDataRepository(asyncRecognizerFactoryMock.Object, asyncRecognizerMock.Object);

  trainerDataRepository.FinalizeTrainer(trainerMock.Object);

  trainerMock.Verify(trainer => trainer.Finalize(), Times.Once());

My method is now:

public void FinalizeTrainer(Trainer wordTrainer)
{
  wordTrainer.Finalize();
}

Also, Moq is 4.0.10827.0 running against .Net 3.5

  • 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-06-11T02:10:44+00:00Added an answer on June 11, 2026 at 2:10 am

    Rename your method to something other than Finalize. If I copy/paste your code and rename the method, it starts to work fine.

    It also generates a compiler warning CS0465, and should be avoided.

    The reason this doesn’t work is that Finalize is actually sort of a reserved name for the class destructor. If you write this C# code:

    public class Trainer
    {
        ~Trainer()
        {
            int x = 1;
        }
    }
    

    The compiler actually names the destructor Finalize() in the IL code:

    .method family hidebysig virtual instance void 
            Finalize() cil managed
    {
      // Code size       16 (0x10)
      .maxstack  1
      .locals init ([0] int32 x)
      .try
      {
        IL_0000:  nop
        IL_0001:  ldc.i4.1
        IL_0002:  stloc.0
        IL_0003:  nop
        IL_0004:  leave.s    IL_000e
      }  // end .try
      finally
      {
        IL_0006:  ldarg.0
        IL_0007:  call       instance void [mscorlib]System.Object::Finalize()
        IL_000c:  nop
        IL_000d:  endfinally
      }  // end handler
      IL_000e:  nop
      IL_000f:  ret
    } // end of method Trainer::Finalize
    

    In fact if you try to add both a destructor and a Finalize method:

    public class Trainer
    {
        ~Trainer()
        {
        }
    
        public virtual Finalize()
        {
        }
    }
    

    This code will no longer compile, because those 2 methods are the same thing. Tricky, eh? 🙂

    It is also noted in ECMA-335:

    I I.10.5.2 Instance finalizer

    The behavior of finalizers is specified
    in Partition I. The finalize method for a particular type is specified
    by overriding the virtual method Finalize in System.Object.

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

Sidebar

Related Questions

This one has us all baffled at work. We have two services running on
So I am baffled by this one. I have a function that is responsible
I thought this would be fairly easy, but I'm totally baffled. I want one
I guess this question will sound familiar, but I am yet another programmer baffled
This one's got me a bit baffled. I've written some extension methods on UIElement
Right... this one had me baffled for a while today so maybe one of
I am completely baffled by this as I have coded several other methods using
I'm just baffled on this one. I'm using linq.js, which is a great library
Alright I'm a bit baffled by this one. Changing an unrelated int property on
I'm baffled by this one. I tried moving the QPainter to it's own def

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.